API Client Example
Example implementation to help you get started with the Nekt Data API.
Python Flask Implementation
We’ve created a reference implementation in Python using Flask that demonstrates how to use the Nekt Data API. This implementation provides a simple REST API server that you can run locally to query your data through Nekt.
Features
- All data is processed in your own cloud
- Simple REST API built with Flask
- Handles authentication with your Nekt API key
- Supports creating queries by table name or SQL
- Handles pagination of results
- Provides health check endpoint
Repository
You can find the full source code on GitHub: github.com/nektcom/data-api-server.
Setup
- Clone the repository:
- Install dependencies using
uv
:
- Run the server:
Once running, the server will be available at http://localhost:5001
.
Using the API
Authentication
All requests (except health check) require your Nekt API key in the x-api-key
header:
Creating Queries
You can create queries in two ways:
Using Layer and Table Names
Using SQL Query
Getting Results
Once you have a query slug (e.g.: explorer-query-8OSP
) from the query creation endpoint, you can fetch results:
Results are paginated with 100 records per page:
Continue fetching subsequent pages by incrementing the page_number
parameter until you receive fewer than 100 records or an empty array:
How It Works
The Flask server acts as a middleware between your application and the Nekt Data API:
- It accepts your API requests locally
- Forwards them to Nekt’s Data API using your API key
- Returns the responses directly to your application
This approach provides several benefits:
- Simplifies authentication handling
- Abstracts the complexities of working with the Data API directly
- Provides a reference for implementing your own clients in other languages
Implementation Details
The implementation follows the flow described in the Introduction section. Specifically:
- Creating queries via the
/api/queries
endpoint - Getting results via the
/api/queries/{query_slug}/results
endpoint - Handling pagination to retrieve all results
Next Steps
You can use this implementation as a starting point for your own data API client. Consider:
- Adding caching for frequent queries
- Implementing error handling and retries
- Building additional endpoints for your specific use cases
- Extending the authentication mechanism
For more details on the Data API endpoints themselves, refer to the relevant sections in this documentation.