Skip to main content

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://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 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:

  1. Render client as usual python package via PackageRenderer
  2. 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.

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swagger-codegen-0.1.26.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

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

swagger_codegen-0.1.26-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file swagger-codegen-0.1.26.tar.gz.

File metadata

  • Download URL: swagger-codegen-0.1.26.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.5 Darwin/20.1.0

File hashes

Hashes for swagger-codegen-0.1.26.tar.gz
Algorithm Hash digest
SHA256 b1dd04417329d45f0abfbd005bccff94473cafa868d56ac3b53ea06f4c3f8683
MD5 f27a6380f6acfbc7e110d52a4f43a89b
BLAKE2b-256 02a5ca4c31b2455f938b46518d0d2891ce352675d03e8be7c1d2d5cbc9bc88bf

See more details on using hashes here.

File details

Details for the file swagger_codegen-0.1.26-py3-none-any.whl.

File metadata

  • Download URL: swagger_codegen-0.1.26-py3-none-any.whl
  • Upload date:
  • Size: 31.6 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

Hashes for swagger_codegen-0.1.26-py3-none-any.whl
Algorithm Hash digest
SHA256 9ee2a0a5126b41b4bcd9769ac4a4a8e02989f13f11457f8f59b485a10dd3c1ae
MD5 9894b05eec0f55f50f15d56db281d1bc
BLAKE2b-256 669841802a2287153c0a71d10d77e7b4420f0ed2c3b7e4421cc7f2a2bd925f86

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.31

2 files

0.1.30

2 files

0.1.29

2 files

0.1.28

2 files

0.1.27

2 files

This release

0.1.26 This release

2 files

0.1.25

2 files

0.1.24

2 files

0.1.23

2 files

0.1.22

2 files

0.1.21

2 files

0.1.20

2 files

0.1.19

2 files

0.1.18

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page