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"))
>>> pets = client.pet.findPetsByStatus()
>>> print(pets)
[Pet(category=Category(id=1, name='Dogs'), id=69, name='aHldog', photoUrls=['string'], status='available',...]
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 transfer objects ordered differently. Functionally clients stay the same, but each time the code is generated there are a 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 fixing 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 much 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
Metadata
Release files for swagger-codegen 0.1.31
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swagger-codegen-0.1.31.tar.gz | 21.5 kB | Without provenance | Details for swagger-codegen-0.1.31.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swagger_codegen-0.1.31-py3-none-any.whl | Python 3 | none | any | Details for swagger_codegen-0.1.31-py3-none-any.whl |
Total release size: 54.8 kB
Release files / swagger-codegen-0.1.31.tar.gz
| Download URL | swagger-codegen-0.1.31.tar.gz |
|---|---|
| Size | 21.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a6f53151640a1178f4d291e17718a104a96f16337af25e2988072fc2106b3a1
|
|
BLAKE2b-256 checksum How to use checksums |
77953019581fec32e932e701d1f965fb4ead814dbfffc7c086037c2b1e8f6e7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.6 Darwin/21.1.0
|
Release files / swagger_codegen-0.1.31-py3-none-any.whl
| Download URL | swagger_codegen-0.1.31-py3-none-any.whl |
|---|---|
| Size | 33.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b97b52ebb50f4408858a3bf58ad65d7241e00aa7803f4f350c8f9f1809b67ad3
|
|
BLAKE2b-256 checksum How to use checksums |
dec820a6dddd8b99b45f8bd5e016afa9c18551c53f78d749e085834670bb227c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.6 Darwin/21.1.0
|
Security for swagger-codegen 0.1.31
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.