This project is a Flask-based web service interfacing with Supabase for data storage and management. It features API key verification and credit-based access control for its endpoints.
- API key verification from Supabase.
- Credit system for API usage.
- User and animal data retrieval based on API key and query parameters.
- Flask
- Supabase
- PostgREST
- Install Required Packages:
pip install Flask supabase postgrest
- Configure Environment Variables:
- Set
SUPABASE_URL
andSUPABASE_KEY
inconsts.py
.
- Set
- Start the Flask Server:
python [filename].py
- API Endpoints:
/v1/animals
: Get animal data based on the name query parameter. Requires API key for access.
- The API key is verified against the Supabase 'api_keys' table.
- Two methods provided:
verify_api_key_from_supabase
andverify_api_key_from_supabase_with_credits
.
- Each API call checks and deducts credits associated with the API key.
- Responses include credit information and relevant data or error messages.
- Errors are logged using a custom logger.
- Exceptions, such as
APIError
from PostgREST, are caught and handled appropriately.
- The
test_platform_functionality
function can be used to test the complete functionality. - It is currently commented out and can be activated for development tests.
- For production, it's recommended to retrieve the API key from request headers for security purposes.
- Contributions are welcome. Please follow the standard pull request process for contributions.