Automatically generate Python API clients from OpenAPI 3.1.0 specifications.
Brij Kishore Pandey Linkedin - https://www.linkedin.com/in/brijpandeyji/ GitHub: honestsoul
- Parses OpenAPI 3.1.0 specifications
- Generates Python client code with type hints
- Supports various authentication methods (API Key, OAuth2, OpenID Connect)
- Implements rate limiting to respect API constraints
- Provides asynchronous support for efficient concurrent requests
- Includes mock response generation for testing
- Offers a simple caching mechanism to optimize API requests
- Supports JSON Schema Draft 2020-12 for improved data validation
Our API Client Generator supports the following HTTP methods:
- GET
- POST
- PUT
- DELETE
- PATCH
- OPTIONS
- HEAD
- TRACE
We currently support the following authentication methods:
- API Key (in header or query parameter)
- OAuth 2.0 (Client Credentials flow)
- OpenID Connect (Client Credentials flow with JWT validation)
You can install the API Client Generator using pip:
pip install api-client-generatorHere's a quick example of how to use the API Client Generator:
from api_client_generator import OpenAPI310Parser, ClientGenerator, AuthHandler
# Parse the OpenAPI 3.1.0 spec
parser = OpenAPI310Parser('https://api.example.com/openapi.json')
parsed_spec = parser.parse()
# Generate the client
generator = ClientGenerator(parsed_spec)
generator.write_client('generated_client')
# Set up authentication
auth_handler = AuthHandler(parsed_spec['security_schemes'])
auth_handler.setup_auth('oauth2', client_id='your-client-id', client_secret='your-client-secret')
# Use the generated client
from generated_client.client import ExampleAPIClient
client = ExampleAPIClient('https://api.example.com', auth_handler)
response = client.get_user(user_id=123)
print(response)-
OpenAPI Support:
- Primarily supports OpenAPI 3.1.0 specifications
- May have limited backwards compatibility with OpenAPI 3.0.x and Swagger 2.0
-
Authentication:
- Supports API Key, OAuth2, and OpenID Connect
- Complex authentication flows may require additional implementation
-
Rate Limiting:
- Implements a simple rate limiting mechanism
- May not cover all complex rate limiting scenarios
-
Asynchronous Support:
- Basic async support provided
- May not cover all edge cases in asynchronous operations
-
Generated Code:
- Generated code may require manual tweaking for complex APIs
- Does not generate comprehensive documentation for the generated client
-
Testing:
- Provides basic mock response generation
- Does not generate comprehensive test suites
-
Caching:
- Implements a simple in-memory caching mechanism
- Does not support distributed caching or persistence
-
Error Handling:
- Basic error handling is implemented
- May not cover all possible API-specific error scenarios
-
Customization:
- Limited options for customizing the generated client code
- May require manual intervention for highly specific requirements
-
API Types:
- Primarily designed for RESTful APIs
- Does not support GraphQL or other API paradigms
-
Language Support:
- Generates Python code only
- Does not support other programming languages
-
Dependencies:
- Relies on external libraries (see requirements.txt)
- May need updates as dependencies evolve
We are committed to improving and expanding the API Client Generator. Here are some of our plans for future development:
-
Enhanced OAuth 2.0 support:
- Add support for Authorization Code flow
- Implement Refresh Token handling
-
Expanded OpenID Connect capabilities:
- Support for additional flows (e.g., Authorization Code flow with PKCE)
- Enhanced ID token validation and claims verification
-
Additional authentication methods:
- Basic Authentication
- Digest Authentication
- JWT Authentication
-
Improved code generation:
- More customization options for generated code
- Support for generating async clients using
asyncioandaiohttp
-
Extended OpenAPI support:
- Full support for all OpenAPI 3.1.0 features
- Backwards compatibility with OpenAPI 3.0.x and Swagger 2.0
-
Enhanced testing capabilities:
- Generate more comprehensive test suites for the API clients
- Improved mock server functionality
-
Documentation improvements:
- Automatic generation of client library documentation
- Interactive API playground generation
-
Performance optimizations:
- Improved caching mechanisms
- Connection pooling and request batching
-
Support for additional API paradigms:
- GraphQL support
- gRPC support
-
Multi-language support:
- Extend code generation to other popular languages (e.g., JavaScript, Java, Go)
This package is compatible with Python 3.9 and 3.10.
Note: There are currently known issues with Python 3.11 due to compatibility problems with some dependencies. We are working on resolving these issues and hope to support Python 3.11 in a future release.
[Rest of your README content]
We welcome contributions and suggestions for additional features or improvements!
For more detailed information about the API Client Generator, please refer to our documentation.
We welcome contributions! Please see our Contributing Guidelines for more details.
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any problems or have any questions, please open an issue on our GitHub issue tracker.