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.
Based on the "RESTful API" category.
Alternatively, view pyswagger alternatives based on common mentions on social networks and blogs.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of pyswagger or a related project?
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.
pyswagger.tests.contrib.client for details
Before running this script, please make sure requests is installed on your environment.
from pyswagger import App, Security
from pyswagger.contrib.client.requests import Client
from pyswagger.utils import jp_compose
# load Swagger resource file into App object
app = App._create_('http://petstore.swagger.io/v2/swagger.json')
auth = Security(app)
auth.update_with('api_key', '12312312312312312313q') # api key
auth.update_with('petstore_auth', '12334546556521123fsfss') # oauth2
# init swagger client
client = Client(auth)
# a dict is enough for representing a Model in Swagger
pet_Tom=dict(id=1, name='Tom', photoUrls=['http://test'])
# a request to create a new pet
client.request(app.op['addPet'](body=pet_Tom))
# - access an Operation object via App.op when operationId is defined
# - a request to get the pet back
req, resp = app.op['getPetById'](petId=1)
# prefer json as response
req.produce('application/json')
pet = client.request((req, resp)).data
assert pet.id == 1
assert pet.name == 'Tom'
# new ways to get Operation object corresponding to 'getPetById'.
# 'jp_compose' stands for JSON-Pointer composition
req, resp = app.resolve(jp_compose('/pet/{petId}', base='#/paths')).get(petId=1)
req.produce('application/json')
pet = client.request((req, resp)).data
assert pet.id == 1
We support pip installtion.
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.
pip install requests
If you want to test a local tornado server, please make sure tornado is ready on your environment
pip install tornado
We also provide native client for flask app, but to use it, flask is also required
pip install flask
All exported API are described in following sections. A diagram about relations between components
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
python -m pytest -s -v --cov=pyswagger --cov-config=.coveragerc pyswagger/tests
Do not miss the trending, packages, news and articles with our weekly report.