Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pyswagger

> 编程语言
Open source

An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.

393 stars0 likes0 views
WebsiteGitHub

About

An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.

pyswagger

A python client for Swagger enabled REST API. It wouldn't be easier to try Swagger REST API by Swagger-UI. However, when it's time to unittest your API, the first option you find would be Swagger-codegen, but the better option is us.

This project is developed after swagger-py, which is a nicely implemented one, and inspired many aspects of this project. Another project is flex, which focuses on parameter validation, try it if you can handle other parts by yourselves. For other projects related to Swagger tools in python, check here.

pyswagger is much easier to use (compared to swagger-codegen, you don't need to prepare a scala environment) and tries hard to fully supports Swagger Spec in all aspects.

  • NEWs: upcoming support for OpenAPI 3.0
  • Features
  • Tutorial
  • Quick Start
  • Installation
  • Reference
  • Contributors
  • Contribution Guideline
  • FAQ
  • Changes

Features

  • convert Swagger Document from older version to newer one. (ex. convert from 1.2 to 2.0)
  • support Swagger 1.2, 2.0 on python 2.6, 2.7, 3.3, 3.5, 3.6
  • support YAML via Pretty-YAML
  • support $ref to External Document, multiple swagger.json will be organized into a group of App. And external document with self-describing resource is also supported (refer to issue).
  • type safe, input/output are converted to python types according to Data Type described in Swagger. You don't need to touch any json schema when using pyswagger. Limitations like minimum/maximum or enum are also checked. Model inheritance also supported.
  • provide function App.validate to check validity of the loaded API definition according to spec.
  • builtin client implementation based on various http clients in python. For usage of these clients, please refer to pyswagger.tests.contrib.client for details
    • requests
    • tornado.httpclient.AsyncHTTPClient
    • flask.testing.FlaskClient
    • webapp2
  • not implemented parts, fire me a bug if you need it
    • Swagger 2.0
      • Schema.pattern
      • Scheme.patternProperties
      • Schema.readonly
      • Schema.allowEmptyValue
      • A scanner to validate schema
    • A WebSocket client
    • dump extension field

Tutorial

  • Initialization
  • Making a Request
  • Access the Response
  • Testing a Local Server
  • Converting Document into another version
  • Exntending Primitive Factory for user-defined primitives
  • Rendering Random Requests for BlackBox Testing
  • Operation MIME Support
  • Test with Invalid Input
  • Load Spec from a Restricted Service
  • Customized Headers

Quick Start

Before running this script, please make sure requests is installed on your environment.

…

Installation

We support pip installtion.

bash
pip install pyswagger

Additional dependencies must be prepared before firing a request. If you are going to access a remote/local web server, you must install requests first.

bash
pip install requests

If you want to test a local tornado server, please make sure tornado is ready on your environment

bash
pip install tornado

We also provide native client for flask app, but to use it, flask is also required

bash
pip install flask

Reference

All exported API are described in following sections.

  • App
  • SwaggerClient
  • Security

Contributors

  • Marcin Goliński
  • Andrey Mikhailov
  • Telepenin Nikolay
  • WangJiannan

Contribution Guildeline

report an issue:

  • issues can be reported here
  • include swagger.json if possible
  • turn on logging and report with messages on console
python
import logging
logger = logging.getLogger('pyswagger')

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
console.setFormatter(formatter)

logger.addHandler(console)
logger.setLevel(logging.DEBUG)

... your stuff
  • describe expected behavior, or more specific, the input/output

submit a PR

  • test included
  • only PR to develop would be accepted

env preparation

bash
pip install -r requirement-dev.txt

unit testing

bash
python -m pytest -s -v --cov=pyswagger --cov-config=.coveragerc pyswagger/tests

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythonopenapipythonswagger

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言