restcodegen


Namerestcodegen JSON
Version 1.1.1 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2025-07-10 21:40:59
maintainerNone
docs_urlNone
authorMenshikov Valeriy Sergeevich
requires_python<4.0,>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RestCodeGen

[![PyPI version](https://img.shields.io/pypi/v/restcodegen.svg)](https://pypi.org/project/restcodegen)
[![Python versions](https://img.shields.io/pypi/pyversions/restcodegen.svg)](https://pypi.python.org/pypi/restcodegen)
[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/ValeriyMenshikov/restcodegen/python-test.yml?branch=main)](https://github.com/ValeriyMenshikov/restcodegen/actions/workflows/python-test.yml)
[![Coverage Status](https://coveralls.io/repos/github/ValeriyMenshikov/restcodegen/badge.svg?branch=main)](https://coveralls.io/github/ValeriyMenshikov/restcodegen?branch=main)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ValeriyMenshikov/restcodegen/blob/main/LICENSE)
[![Downloads](https://img.shields.io/pypi/dm/restcodegen.svg)](https://pypistats.org/packages/restcodegen)
[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)

<p align="center">
  <b>Generate Python clients from OpenAPI specifications with ease</b>
</p>

## 🚀 Overview

RestCodeGen is a powerful tool for automatically generating Python client libraries from OpenAPI 3 specifications. It streamlines the process of interacting with REST APIs, allowing developers and testers to quickly integrate with services that provide OpenAPI documentation.

### ✨ Key Features

- **Easy Client Generation**: Create Python clients with a single command
- **Async Support**: Generate both synchronous and asynchronous clients
- **Selective API Generation**: Choose specific API tags to include
- **Built-in Logging**: Integrated with structlog for comprehensive request/response tracking
- **Customizable**: Use your own HTTPX client for advanced configurations
- **Type Hints**: All generated code includes proper type annotations

## 📦 Installation

RestCodeGen requires Python 3.11 or higher. Install it using pip:

```bash
pip install restcodegen
```

Or with Poetry:

```bash
poetry add restcodegen
```

## 🔧 Usage

### Basic Command

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

### Command Parameters

| Parameter | Short | Description | Required | Default |
|-----------|-------|-------------|----------|---------|
| `--url` | `-u` | URL of the OpenAPI specification | Yes | - |
| `--service-name` | `-s` | Name of the service | Yes | - |
| `--async-mode` | `-a` | Enable asynchronous client generation | No | `false` |
| `--api-tags` | `-t` | Comma-separated list of API tags to generate | No | All APIs |

### Example

Generate a client for the Petstore API:

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

## 📁 Generated Structure

After successful execution, a client library will be created with the following structure:

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

## 💻 Using the Generated Client

The generated client includes built-in logging with `structlog` and supports custom HTTPX clients:

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

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

# Create and use the client
if __name__ == '__main__':
    # Configure the base URL
    configuration = Configuration(host="https://petstore3.swagger.io/api/v3")
    
    # Use the built-in client
    api_client = Client(configuration)
    
    # Or use your custom HTTPX client
    # import httpx
    # api_client = httpx.Client()  # or httpx.AsyncClient() for async mode
    
    # Initialize the API
    pet_api = PetApi(api_client)
    
    # Make API calls
    response = pet_api.get_pet_pet_id(pet_id=1)
    print(response)
```

## 🔄 Development Workflow

1. Install development dependencies:
   ```bash
   poetry install
   ```

2. Run tests:
   ```bash
   poetry run pytest
   ```

3. Check code quality:
   ```bash
   poetry run ruff check .
   poetry run mypy .
   ```

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---

## 🤝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

## 📬 Contact

For questions or feedback, please open an issue in the repository.

---

<p align="center">
  <i>RestCodeGen - Making API integration simple and efficient</i>
</p>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "restcodegen",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Menshikov Valeriy Sergeevich",
    "author_email": "valeriy.menshikov.1989@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/30/0e/49ac079b69d3eb38ab95a8168d6996c219debbc96cdb3f04015baf019356/restcodegen-1.1.1.tar.gz",
    "platform": null,
    "description": "# RestCodeGen\n\n[![PyPI version](https://img.shields.io/pypi/v/restcodegen.svg)](https://pypi.org/project/restcodegen)\n[![Python versions](https://img.shields.io/pypi/pyversions/restcodegen.svg)](https://pypi.python.org/pypi/restcodegen)\n[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/ValeriyMenshikov/restcodegen/python-test.yml?branch=main)](https://github.com/ValeriyMenshikov/restcodegen/actions/workflows/python-test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/ValeriyMenshikov/restcodegen/badge.svg?branch=main)](https://coveralls.io/github/ValeriyMenshikov/restcodegen?branch=main)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ValeriyMenshikov/restcodegen/blob/main/LICENSE)\n[![Downloads](https://img.shields.io/pypi/dm/restcodegen.svg)](https://pypistats.org/packages/restcodegen)\n[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)\n\n<p align=\"center\">\n  <b>Generate Python clients from OpenAPI specifications with ease</b>\n</p>\n\n## \ud83d\ude80 Overview\n\nRestCodeGen is a powerful tool for automatically generating Python client libraries from OpenAPI 3 specifications. It streamlines the process of interacting with REST APIs, allowing developers and testers to quickly integrate with services that provide OpenAPI documentation.\n\n### \u2728 Key Features\n\n- **Easy Client Generation**: Create Python clients with a single command\n- **Async Support**: Generate both synchronous and asynchronous clients\n- **Selective API Generation**: Choose specific API tags to include\n- **Built-in Logging**: Integrated with structlog for comprehensive request/response tracking\n- **Customizable**: Use your own HTTPX client for advanced configurations\n- **Type Hints**: All generated code includes proper type annotations\n\n## \ud83d\udce6 Installation\n\nRestCodeGen requires Python 3.11 or higher. Install it using pip:\n\n```bash\npip install restcodegen\n```\n\nOr with Poetry:\n\n```bash\npoetry add restcodegen\n```\n\n## \ud83d\udd27 Usage\n\n### Basic Command\n\n```bash\nrestcodegen generate -u \"http://example.com/openapi.json\" -s \"my-service\" -a false\n```\n\n### Command Parameters\n\n| Parameter | Short | Description | Required | Default |\n|-----------|-------|-------------|----------|---------|\n| `--url` | `-u` | URL of the OpenAPI specification | Yes | - |\n| `--service-name` | `-s` | Name of the service | Yes | - |\n| `--async-mode` | `-a` | Enable asynchronous client generation | No | `false` |\n| `--api-tags` | `-t` | Comma-separated list of API tags to generate | No | All APIs |\n\n### Example\n\nGenerate a client for the Petstore API:\n\n```bash\nrestcodegen generate -u \"https://petstore3.swagger.io/api/v3/openapi.json\" -s \"petstore\" -a false\n```\n\n## \ud83d\udcc1 Generated Structure\n\nAfter successful execution, a client library will be created with the following structure:\n\n```\n\u2514\u2500\u2500 clients                      \n     \u2514\u2500\u2500 http     \n        \u251c\u2500\u2500 schemas               # OpenAPI 3.0.0 schemas for all generated APIs                   \n        \u2514\u2500\u2500 service_name          # Service name     \n            \u251c\u2500\u2500 apis              # API client classes                    \n            \u2514\u2500\u2500 models            # Pydantic models   \n```\n\n## \ud83d\udcbb Using the Generated Client\n\nThe generated client includes built-in logging with `structlog` and supports custom HTTPX clients:\n\n```python\nfrom restcodegen.restclient import Client, Configuration\nfrom clients.http.petstore import PetApi\nimport structlog\n\n# Configure logging\nstructlog.configure(\n    processors=[\n        structlog.processors.JSONRenderer(\n            indent=4,\n            ensure_ascii=True,\n        )\n    ]\n)\n\n# Create and use the client\nif __name__ == '__main__':\n    # Configure the base URL\n    configuration = Configuration(host=\"https://petstore3.swagger.io/api/v3\")\n    \n    # Use the built-in client\n    api_client = Client(configuration)\n    \n    # Or use your custom HTTPX client\n    # import httpx\n    # api_client = httpx.Client()  # or httpx.AsyncClient() for async mode\n    \n    # Initialize the API\n    pet_api = PetApi(api_client)\n    \n    # Make API calls\n    response = pet_api.get_pet_pet_id(pet_id=1)\n    print(response)\n```\n\n## \ud83d\udd04 Development Workflow\n\n1. Install development dependencies:\n   ```bash\n   poetry install\n   ```\n\n2. Run tests:\n   ```bash\n   poetry run pytest\n   ```\n\n3. Check code quality:\n   ```bash\n   poetry run ruff check .\n   poetry run mypy .\n   ```\n\n## \ud83d\udcc4 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n## \ud83e\udd1d Contributing\n\nContributions are welcome! Feel free to open issues or submit pull requests.\n\n## \ud83d\udcec Contact\n\nFor questions or feedback, please open an issue in the repository.\n\n---\n\n<p align=\"center\">\n  <i>RestCodeGen - Making API integration simple and efficient</i>\n</p>\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "1.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f8512a512749c3454aaefa7afdcdb43e78353b0105fee4ba88ce2752ad21888",
                "md5": "89e1841fd8158e4a5e522a6ab9dfcadb",
                "sha256": "cdec3c31a8c66e68a890787546e52512cf615105b75b9b85f66e5eb2b9ec0dce"
            },
            "downloads": -1,
            "filename": "restcodegen-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89e1841fd8158e4a5e522a6ab9dfcadb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 19836,
            "upload_time": "2025-07-10T21:40:58",
            "upload_time_iso_8601": "2025-07-10T21:40:58.403160Z",
            "url": "https://files.pythonhosted.org/packages/9f/85/12a512749c3454aaefa7afdcdb43e78353b0105fee4ba88ce2752ad21888/restcodegen-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "300e49ac079b69d3eb38ab95a8168d6996c219debbc96cdb3f04015baf019356",
                "md5": "b8bb6179a9582cbc5c08cc6660c23115",
                "sha256": "775a2d9c55f780c55a8fb73b9e42f77b01d6bf04603d9728c2149d8ca05662b2"
            },
            "downloads": -1,
            "filename": "restcodegen-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b8bb6179a9582cbc5c08cc6660c23115",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 16854,
            "upload_time": "2025-07-10T21:40:59",
            "upload_time_iso_8601": "2025-07-10T21:40:59.721152Z",
            "url": "https://files.pythonhosted.org/packages/30/0e/49ac079b69d3eb38ab95a8168d6996c219debbc96cdb3f04015baf019356/restcodegen-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-10 21:40:59",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "restcodegen"
}
        
Elapsed time: 1.60486s