Generate API clients by parsing Swagger definitions
Swagger codegen for Python
pip install swagger-codegen
# Generate Petstore Api client using 'petstore' package name. swagger_codegen generate http://petstore.swagger.io:8080/api/v3/openapi.json petstore python Python 3.8.1 (default, Jan 23 2020, 13:58:52) [Clang 11.0.0 (clang-1188.8.131.52)] 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://petstore.swagger.io:8080")) >>> 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 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
- Render client as installable python package via
You can choose what renderer to use by specifying
renderer key in
file. Please see
.swagger-codegen.toml.example for allowed values.
- 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.
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 in not optimized yet and mostly dirty because the project was born as a holiday prototype.
example directory may be out of sync with actual generated code.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size swagger_codegen-0.1.15-py3-none-any.whl (27.7 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size swagger-codegen-0.1.15.tar.gz (17.5 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for swagger_codegen-0.1.15-py3-none-any.whl