Skip to content

honestsoul/python-api-client-generator

Repository files navigation

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:

  1. GET
  2. POST
  3. PUT
  4. DELETE
  5. PATCH
  6. OPTIONS
  7. HEAD
  8. TRACE

Supported Authentication Methods

We currently support the following authentication methods:

  1. API Key (in header or query parameter)
  2. OAuth 2.0 (Client Credentials flow)
  3. 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

  1. OpenAPI Support:

    • Primarily supports OpenAPI 3.1.0 specifications
    • May have limited backwards compatibility with OpenAPI 3.0.x and Swagger 2.0
  2. Authentication:

    • Supports API Key, OAuth2, and OpenID Connect
    • Complex authentication flows may require additional implementation
  3. Rate Limiting:

    • Implements a simple rate limiting mechanism
    • May not cover all complex rate limiting scenarios
  4. Asynchronous Support:

    • Basic async support provided
    • May not cover all edge cases in asynchronous operations
  5. Generated Code:

    • Generated code may require manual tweaking for complex APIs
    • Does not generate comprehensive documentation for the generated client
  6. Testing:

    • Provides basic mock response generation
    • Does not generate comprehensive test suites
  7. Caching:

    • Implements a simple in-memory caching mechanism
    • Does not support distributed caching or persistence
  8. Error Handling:

    • Basic error handling is implemented
    • May not cover all possible API-specific error scenarios
  9. Customization:

    • Limited options for customizing the generated client code
    • May require manual intervention for highly specific requirements
  10. API Types:

    • Primarily designed for RESTful APIs
    • Does not support GraphQL or other API paradigms
  11. Language Support:

    • Generates Python code only
    • Does not support other programming languages
  12. 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:

  1. Enhanced OAuth 2.0 support:

    • Add support for Authorization Code flow
    • Implement Refresh Token handling
  2. Expanded OpenID Connect capabilities:

    • Support for additional flows (e.g., Authorization Code flow with PKCE)
    • Enhanced ID token validation and claims verification
  3. Additional authentication methods:

    • Basic Authentication
    • Digest Authentication
    • JWT Authentication
  4. Improved code generation:

    • More customization options for generated code
    • Support for generating async clients using asyncio and aiohttp
  5. Extended OpenAPI support:

    • Full support for all OpenAPI 3.1.0 features
    • Backwards compatibility with OpenAPI 3.0.x and Swagger 2.0
  6. Enhanced testing capabilities:

    • Generate more comprehensive test suites for the API clients
    • Improved mock server functionality
  7. Documentation improvements:

    • Automatic generation of client library documentation
    • Interactive API playground generation
  8. Performance optimizations:

    • Improved caching mechanisms
    • Connection pooling and request batching
  9. Support for additional API paradigms:

    • GraphQL support
    • gRPC support
  10. 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.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages