Generate API clients by parsing Swagger definitions
Project description
Swagger codegen for Python
Installation
pip install swagger-codegen
Swagger version
Currently only OpenApi 3.x (aka Swagger 3) is supported.
Usage example
# Generate Petstore Api client using 'petstore' package name.
swagger_codegen generate https://petstore3.swagger.io/api/v3/openapi.json petstore
python
Python 3.8.1 (default, Jan 23 2020, 13:58:52)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from petstore import new_client, Configuration
>>> from swagger_codegen.api.adapter.requests import RequestsAdapter
>>> from petstore.apis.user.createUser import User
>>> client = new_client(RequestsAdapter(), Configuration(host="http://petstore3.swagger.io"))
>>> print(client.user.createUser(User(id=1, username="Swagger-Codegen")))
id=1 username='Swagger-Codegen' firstName=None lastName=None email=None password=None phone=None userStatus=0
You can see example source code for PetStore Api in example directory of a project.
You can test example client with following command:
# Run from project directory.
python -m example.petstore_example
Code generators (also known as renderers)
There are two code generator strategies in project:
- Render client as usual python package via
PackageRenderer
- Render client as installable python package via
InstallablePackageRenderer
You can choose what renderer to use by specifying renderer
key in .swagger-codegen.toml
file. Please see .swagger-codegen.toml.example
for allowed values.
Known issues
- Content of generated files differs run-to-run because each time functions or data data transfer objects ordered differently. Functionally clients stay the same, but each time the code is generated there are large diff generated by git.
- Not fully Openapi compliant: the project was built to fulfill my personal needs: a support for FastAPI-generated schemas and I needed this feature quickly, that is why there are too many large dependencies (
schemathesis
) and incompatibilities. Anyway, I'm looking forward to fix this issues by time. - There are may be delays in reaction to issues due to small amount of free time (however PR's with tests are merged asap).
Work in progress
Though library gives nice results for generated API, it is still in development. Some tests are missing. API is a subject to change until stable release.
Anyway backward compatibility will be kept as most as possible.
The code is not optimized yet and mostly dirty because the project was born as a holiday prototype.
Also example
directory may be out of sync with actual generated code.
Contributors
You can see all people who helped this project at the contributors page
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 swagger-codegen-0.1.30.tar.gz
.
File metadata
- Download URL: swagger-codegen-0.1.30.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.5 Darwin/20.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 363276dc90d57ff63d591ea34ae1f6799c09c520217778098b497e860833c401 |
|
MD5 | e39cd60ecc84513970924cbda3a0e266 |
|
BLAKE2b-256 | 83b7bfd535d78768059ec8c5a8ff94300278efac50fe463f5f224a2760ddf2b8 |
File details
Details for the file swagger_codegen-0.1.30-py3-none-any.whl
.
File metadata
- Download URL: swagger_codegen-0.1.30-py3-none-any.whl
- Upload date:
- Size: 32.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.8.5 Darwin/20.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c0df19322150e74f641f033df99f811a61349a9364fe1fd45399431a758bdfb |
|
MD5 | f9d33d56f8978e410d3b2382620b73ce |
|
BLAKE2b-256 | c4264a285fee8d259fea5c017ee9fa0838ce089e5b513b54b20c97975f5dbbe4 |