Automatically generate Python API clients from OpenAPI specifications
Project description
API Client Generator
Automatically generate Python API clients from OpenAPI 3.1.0 specifications.
Author
Brij Kishore Pandey Linkedin - https://www.linkedin.com/in/brijpandeyji/ GitHub: honestsoul
Features and Capabilities
- 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
Supported HTTP Methods
Our API Client Generator supports the following HTTP methods:
- GET
- POST
- PUT
- DELETE
- PATCH
- OPTIONS
- HEAD
- TRACE
Supported Authentication Methods
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)
Installation
You can install the API Client Generator using pip:
pip install api-client-generator
Quick Start
Here'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)
Limitations
-
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
Future Plans
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
asyncio
andaiohttp
-
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)
Compatibility
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!
Documentation
For more detailed information about the API Client Generator, please refer to our documentation.
Contributing
We welcome contributions! Please see our Contributing Guidelines for more details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any problems or have any questions, please open an issue on our GitHub issue tracker.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file api_client_generator-0.1.0.tar.gz
.
File metadata
- Download URL: api_client_generator-0.1.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acfaedbdfa4e16770dc8801b781e68e79951f8dd4d82a45abeb6ff47cbd1b800 |
|
MD5 | c27222d6c1b3dde24e542e2f50deb359 |
|
BLAKE2b-256 | f0444dc4bc10e5c735dd6f3a0baa3e7d888763573261fa133feefa9c69e85291 |
File details
Details for the file api_client_generator-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: api_client_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7e531e3065b8270abf9a92f83f9395e0f61af20bdd20418b0924aeab129eefb |
|
MD5 | 06adef6515402542d043adaafca81b4e |
|
BLAKE2b-256 | aadace5d4a63a6fd5fc0f767c38ab828cdfc6c7499bcf367b5c5b433118b9a9a |