Skip to main content

No project description provided

Project description

RestCodeGen

RestCodeGen is a tool for generating Python clients based on OpenAPI 3 specifications.
This tool enables testers to quickly create client libraries for interacting with REST APIs implemented with OpenAPI.

Installation

To install, you need the required dependencies. Make sure you have Python 3.10 or higher installed.

pip install restcodegen

Usage

Once installed, you can use the restcodegen command to generate a client.

Command Syntax

restcodegen generate -u "http://example.com/openapi.json" -s "my-service" -a false

Command Parameters

- --url, -u: URL of the OpenAPI specification (required).
- --service-name, -s: Name of the service (required).
- --async-mode, -a: Flag to enable asynchronous client generation (default is false).
- --api-tags, -t: Comma-separated list of API tags to generate (default is all APIs).

Example

To generate a client for an API available at the URL https://petstore3.swagger.io/api/v3/openapi.json, you can use the following command:

restcodegen generate -u "https://petstore3.swagger.io/api/v3/openapi.json" -s "petstore" -a false

Result

After a successful command execution, a client library will be created with a name corresponding to the provided service name. The generated files will contain classes and methods for interacting with the API described in the provided specification.

Structure:

└── clients                      
     └── http     
        ├── schemas               # OpenAPI 3.0.0 schemas for all generated apis                   
        └── service_name          # Service name     
            ├── apis              # APIs                    
            └── models            # Pydantic models   

Generated client usage

The generated API client includes built-in logging using structlog, which allows you to easily track API requests and responses. Additionally, instead of using the built-in ApiClient, you can provide your own HTTPX client for more customization.

Here is an example of how to use the generated client:

from restcodegen.restclient import Client, Configuration
from clients.http.petstore import PetApi
import structlog

structlog.configure(
    processors=[
        structlog.processors.JSONRenderer(
            indent=4,
            ensure_ascii=True,
        )
    ]
)

if __name__ == '__main__':
    configuration = Configuration(host="https://petstore3.swagger.io/api/v3")
    api_client = Client(configuration)  # You can replace this with your custom httpx client
    # apiclient = httpx.AsyncClient()  # Uncomment if using a custom HTTPX client
    pet_api = PetApi(api_client)
    response = pet_api.get_pet_pet_id(pet_id=1)
    print(response)

License

This project is licensed under the MIT License. See the LICENSE file for more information.


I hope that RestCodeGen will simplify your work with REST APIs. If you have any questions or suggestions, please create an issue in the repository.

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

restcodegen-1.0.2.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

restcodegen-1.0.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file restcodegen-1.0.2.tar.gz.

File metadata

  • Download URL: restcodegen-1.0.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for restcodegen-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b555953e26fb61f1c3b4db1a339d9e8b8a718263fde6bb2daa1577bc74e505b9
MD5 d5ffaa6dca196609e5545b1089e2358a
BLAKE2b-256 907a8a07356c56e8ce385ffa4129be441e42ae3538bfeded93ec84bb0bf3654b

See more details on using hashes here.

File details

Details for the file restcodegen-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: restcodegen-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for restcodegen-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5580d49186c106be5c0f62734c5bae113a6f6b5ebe130cb5058d54b496bad95d
MD5 09361745a53d691e33de7305049b7b17
BLAKE2b-256 7cae96e23fd21f501f6f9c1889bdd1e95ad503e0acd93fea3f622689f68ef702

See more details on using hashes here.

Supported by

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