Skip to main content

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:

  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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

api_client_generator-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

api_client_generator-0.1.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

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

Hashes for api_client_generator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 acfaedbdfa4e16770dc8801b781e68e79951f8dd4d82a45abeb6ff47cbd1b800
MD5 c27222d6c1b3dde24e542e2f50deb359
BLAKE2b-256 f0444dc4bc10e5c735dd6f3a0baa3e7d888763573261fa133feefa9c69e85291

See more details on using hashes here.

File details

Details for the file api_client_generator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for api_client_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7e531e3065b8270abf9a92f83f9395e0f61af20bdd20418b0924aeab129eefb
MD5 06adef6515402542d043adaafca81b4e
BLAKE2b-256 aadace5d4a63a6fd5fc0f767c38ab828cdfc6c7499bcf367b5c5b433118b9a9a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page