Skip to main content

Generate API clients by parsing Swagger definitions

Project description

Swagger codegen for Python

Installation

pip install swagger-codegen

Usage example

# 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-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

  • livestalker
  • coderfromhere

Project details


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.18.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

swagger_codegen-0.1.18-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: swagger-codegen-0.1.18.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.8.1 Darwin/19.6.0

File hashes

Hashes for swagger-codegen-0.1.18.tar.gz
Algorithm Hash digest
SHA256 d9e4396de7cd3b9ad1946d765ab0e42c7eedaeb7af650de76f4a2da481cade30
MD5 0bb72a43942ac7a6e16e44daf96b4b93
BLAKE2b-256 0df5f1ab3c75a8af3de0d8b7394a4fe00b8e4ed88f8deab3605f28ee19cd8514

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for swagger_codegen-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 eeb8676021660acdd9abaa02ff6f34ee80be2497eaa2790bf1b3e1c276e97511
MD5 0ac7ab3d4e54205481646095dccc3edb
BLAKE2b-256 fc6d6f645e867528744b7dfa3a43bae2ead78292882dd623e051ca80c5b8ab7b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page