Skip to main content
This tutorial shows you how to build a custom Lumos connector for your application. By the end, you’ll have:
  1. A working test server that simulates your application’s API
  2. A fully functional Lumos connector that integrates with this API
  3. The knowledge to adapt this connector for your real application

Setup Overview

You work with two components:
  1. Mock API Server: A FastAPI application that simulates your application’s API endpoints
  2. Lumos Connector: A Python package that translates between your API and Lumos

Part 1: Setting Up the Test Environment

Step 1: Install Dependencies

Step 2: Set Up the Mock API Server

Make sure to create the Mock API Server file, follow the instructions in Mock API Server for Testing Lumos Connectors. From a new terminal window, start the mock API server:
The server should now be running at http://localhost:8000. You can access the API documentation at http://localhost:8000/docs. Do not close this terminal window/session.

Step 3: Test the API Server

Verify that the server is working correctly. From your previous terminal window, run:

Part 2: Creating the Lumos Connector

Step 1: Scaffold a New Connector

Now create a new Lumos connector that connects to the mock API:

Step 2: Configure the Connector Settings

Edit mockapp_connector/settings.py to define the configuration settings users will provide:

Step 3: Update Constants

Edit mockapp_connector/constants.py to set the API base URL:

Step 4: Define Resource and Entitlement Types

Edit mockapp_connector/enums.py to match the types in the mock API:

Step 5: Create API Client

Edit mockapp_connector/client.py to create a client for the mock API:

Step 6: Implement Read Capabilities

Edit mockapp_connector/capabilities_read.py to implement the required read capabilities:

Step 7: Implement Write Capabilities

Edit mockapp_connector/capabilities_write.py to implement write capabilities:

Step 8: Update the User DTO

Edit mockapp_connector/dto/user.py to add the required API field display_name to the CreateAccount model:

Step 9: Configure the Integration

Finally, edit mockapp_connector/integration.py to register all capabilities:

Part 3: Testing Your Connector

Step 1: Run Basic Tests

First, verify that the connector compiles correctly:

Step 2: Test with the Mock API

Now, with the mock API server running, test the connector against it:
If everything is configured correctly, you should get successful responses from both commands.

Step 3: Test Write Operations

Next, test a write operation:

Part 4: Adapting for Your Real Application

To adapt this connector for your real application, you’ll need to:
  1. Update the settings: Modify settings.py to include any configuration specific to your application
  2. Adjust the client: Update client.py to match your API’s endpoints and request/response formats
  3. Map data models: Update the transformation logic in capabilities_read.py and capabilities_write.py
  4. Change authentication: Update integration.py to use the correct auth type for your application

Key Files and Their Purpose

Here’s a summary of the key files and what they’re responsible for:

Common Patterns and Best Practices

  1. Error Handling: Use try/except blocks around API calls to handle errors gracefully
  2. Data Transformation: Create helper functions for transforming between API and Lumos data models
  3. Pagination: Follow the pagination pattern shown in list_accounts
  4. Authentication: Keep authentication logic in the client’s prepare_client_args method
  5. Testing: Use the provided test framework for unit tests

Troubleshooting

  • Authentication Errors: Verify your token is valid and being passed correctly
  • Data Mapping Issues: Check that field names match between your API and Lumos models
  • API Errors: Use httpx.codes to handle different response codes appropriately
  • Pagination Problems: Make sure your pagination logic correctly handles empty results

Next Steps

  1. Implement Tests: Leverage the cases structure and properly test your implementation
  2. Add Documentation: Document any unique behavior or requirements
  3. Deploy: Use the packaging tools to deploy your connector
  4. Monitor: Add logging to help troubleshoot issues in production

Conclusion

You now have a working Lumos connector that can integrate with your application. By following the patterns in this tutorial, you can extend it to support additional capabilities or adapt it for other applications.