{"id":13907956,"url":"https://github.com/pyopenapi/pyswagger","last_synced_at":"2025-07-18T06:31:59.495Z","repository":{"id":19077883,"uuid":"22305196","full_name":"pyopenapi/pyswagger","owner":"pyopenapi","description":"An OpenAPI (fka Swagger) client \u0026 converter in python, which is type-safe, dynamic, spec-compliant.","archived":false,"fork":false,"pushed_at":"2024-06-25T16:58:46.000Z","size":903,"stargazers_count":385,"open_issues_count":45,"forks_count":90,"subscribers_count":14,"default_branch":"develop","last_synced_at":"2024-11-14T13:44:34.198Z","etag":null,"topics":["openapi","python","swagger"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyopenapi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-07-27T06:47:30.000Z","updated_at":"2024-11-01T04:26:26.000Z","dependencies_parsed_at":"2024-06-18T17:01:40.882Z","dependency_job_id":null,"html_url":"https://github.com/pyopenapi/pyswagger","commit_stats":null,"previous_names":["mission-liao/pyswagger"],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyopenapi%2Fpyswagger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyopenapi%2Fpyswagger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyopenapi%2Fpyswagger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyopenapi%2Fpyswagger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyopenapi","download_url":"https://codeload.github.com/pyopenapi/pyswagger/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226361621,"owners_count":17612930,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["openapi","python","swagger"],"created_at":"2024-08-06T23:02:20.995Z","updated_at":"2024-11-25T16:31:14.982Z","avatar_url":"https://github.com/pyopenapi.png","language":"Python","readme":"pyswagger\n=========\n\n[![Build Status](https://travis-ci.org/mission-liao/pyswagger.svg?branch=master)](https://travis-ci.org/mission-liao/pyswagger)\n[![Coverage Status](https://coveralls.io/repos/mission-liao/pyswagger/badge.svg?branch=master\u0026style=flat)](https://coveralls.io/r/mission-liao/pyswagger?branch=master)\n\nA python client for [Swagger](https://helloreverb.com/developers/swagger) enabled REST API. It wouldn't be easier to\ntry Swagger REST API by [Swagger-UI](https://github.com/wordnik/swagger-ui). However, when it's time to **unittest**\nyour API, the first option you find would be [Swagger-codegen](https://github.com/wordnik/swagger-codegen), but the better option is us.\n\nThis project is developed after [swagger-py](https://github.com/digium/swagger-py), which is a nicely implemented one, and inspired many aspects of this project. Another project is [flex](https://github.com/pipermerriam/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](https://github.com/swagger-api/swagger-spec#python).\n\n**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](https://helloreverb.com/developers/swagger) in all aspects.\n\n- [NEWs: upcoming support for OpenAPI 3.0](docs/md/news.md)\n- [Features](README.md#features)\n- [Tutorial](README.md#tutorial)\n- [Quick Start](README.md#quick-start)\n- [Installation](README.md#installation)\n- [Reference](README.md#reference)\n- [Contributors](README.md#contributors)\n- [Contribution Guideline](README.md#contribution-guildeline)\n- [FAQ](docs/md/faq.md)\n- [Changes](CHANGES.md)\n\n---------\n\n## Features\n- convert Swagger Document from older version to newer one. (ex. convert from 1.2 to 2.0)\n- support Swagger **1.2**, **2.0** on python ~~2.6~~, **2.7**, **3.3**, **3.5**, **3.6**\n- support YAML via [Pretty-YAML](https://github.com/mk-fg/pretty-yaml)\n- 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](https://github.com/swagger-api/swagger-spec/issues/219)).\n- type safe, input/output are converted to python types according to [Data Type](https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#43-data-types) 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.\n- provide function **App.validate** to check validity of the loaded API definition according to spec.\n- builtin client implementation based on various http clients in python. For usage of these clients, please refer to `pyswagger.tests.contrib.client` for details\n  - [requests](https://github.com/kennethreitz/requests)\n  - [tornado.httpclient.AsyncHTTPClient](http://tornado.readthedocs.org/en/latest/httpclient.html)\n  - [flask.testing.FlaskClient](http://flask.pocoo.org/docs/0.10/api/#flask.testing.FlaskClient)\n  - [webapp2](http://webapp2.readthedocs.io/en/latest/guide/testing.html)\n- not implemented parts, fire me a bug if you need it\n  - [ ] Swagger 2.0\n    - [ ] Schema.pattern\n    - [ ] Scheme.patternProperties\n    - [ ] Schema.readonly\n    - [ ] Schema.allowEmptyValue\n    - [ ] A scanner to validate schema\n  - [ ] A WebSocket client\n  - [ ] dump extension field\n\n---------\n\n## Tutorial\n\n- [Initialization](docs/md/tutorial/init.md)\n- [Making a Request](docs/md/tutorial/request.md)\n- [Access the Response](docs/md/tutorial/response.md)\n- [Testing a Local Server](docs/md/tutorial/local.md)\n- [Converting Document into another version](docs/md/tutorial/converter.md)\n- [Exntending Primitive Factory for user-defined primitives](docs/md/tutorial/extend_prim.md)\n- [Rendering Random Requests for BlackBox Testing](docs/md/tutorial/render.md)\n- [Operation MIME Support](docs/md/tutorial/mime.md)\n- [Test with Invalid Input](docs/md/tutorial/invalid.md)\n- [Load Spec from a Restricted Service](docs/md/tutorial/restricted_service.md)\n- [Customized Headers](docs/md/tutorial/customized_headers.md)\n\n---------\n\n## Quick Start\n\nBefore running this script, please make sure [requests](https://github.com/kennethreitz/requests) is installed on your environment.\n\n```python\nfrom pyswagger import App, Security\nfrom pyswagger.contrib.client.requests import Client\nfrom pyswagger.utils import jp_compose\n\n# load Swagger resource file into App object\napp = App._create_('http://petstore.swagger.io/v2/swagger.json')\n\nauth = Security(app)\nauth.update_with('api_key', '12312312312312312313q') # api key\nauth.update_with('petstore_auth', '12334546556521123fsfss') # oauth2\n\n# init swagger client\nclient = Client(auth)\n\n# a dict is enough for representing a Model in Swagger\npet_Tom=dict(id=1, name='Tom', photoUrls=['http://test']) \n# a request to create a new pet\nclient.request(app.op['addPet'](body=pet_Tom))\n\n# - access an Operation object via App.op when operationId is defined\n# - a request to get the pet back\nreq, resp = app.op['getPetById'](petId=1)\n# prefer json as response\nreq.produce('application/json')\npet = client.request((req, resp)).data\nassert pet.id == 1\nassert pet.name == 'Tom'\n\n# new ways to get Operation object corresponding to 'getPetById'.\n# 'jp_compose' stands for JSON-Pointer composition\nreq, resp = app.resolve(jp_compose('/pet/{petId}', base='#/paths')).get(petId=1)\nreq.produce('application/json')\npet = client.request((req, resp)).data\nassert pet.id == 1\n```\n\n---------\n\n## Installation\nWe support pip installtion.\n```bash\npip install pyswagger\n```\n\nAdditional dependencies must be prepared before firing a request. If you are going to access a remote/local web server, you must install [requests](https://github.com/kennethreitz/requests) first.\n```bash\npip install requests\n```\n\nIf you want to test a local tornado server, please make sure tornado is ready on your environment\n``` bash\npip install tornado\n```\n\nWe also provide native client for flask app, but to use it, flask is also required\n``` bash\npip install flask\n```\n\n\n---------\n\n## Reference\nAll exported API are described in following sections. ![A diagram about relations between components](https://docs.google.com/drawings/d/1DZiJgl4i9L038UJJp3kpwkWRvcNQktf5h-e4m96_C-k/pub?w=849\u0026h=530)\n\n- [App](docs/md/ref/app.md)\n- [SwaggerClient](docs/md/ref/client.md)\n- [Security](docs/md/ref/security.md)\n\n---------\n\n## Contributors\n- [Marcin Goliński](https://github.com/mjgolinski)\n- [Andrey Mikhailov](https://github.com/zlovred)\n- [Telepenin Nikolay](https://github.com/prefer)\n- [WangJiannan](https://github.com/WangJiannan)\n\n---------\n\n## Contribution Guildeline\n\n#### report an issue:\n- issues can be reported [here](https://github.com/mission-liao/pyswagger/issues)\n- include swagger.json if possible\n- turn on logging and report with messages on console\n```python\nimport logging\nlogger = logging.getLogger('pyswagger')\n\nformatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')\n\nconsole = logging.StreamHandler()\nconsole.setLevel(logging.DEBUG)\nconsole.setFormatter(formatter)\n\nlogger.addHandler(console)\nlogger.setLevel(logging.DEBUG)\n\n... your stuff\n\n```\n\n- describe expected behavior, or more specific, the input/output\n\n#### submit a PR\n- test included\n- only PR to `develop` would be accepted\n\nenv preparation\n```bash\npip install -r requirement-dev.txt\n```\n\nunit testing\n```bash\npython -m pytest -s -v --cov=pyswagger --cov-config=.coveragerc pyswagger/tests\n```\n\n","funding_links":[],"categories":["HarmonyOS","Python"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyopenapi%2Fpyswagger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyopenapi%2Fpyswagger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyopenapi%2Fpyswagger/lists"}