{"id":13837142,"url":"https://github.com/rightlag/pyswagger","last_synced_at":"2025-04-12T14:08:59.500Z","repository":{"id":84983644,"uuid":"49664313","full_name":"rightlag/pyswagger","owner":"rightlag","description":"HTTP client for Open API","archived":false,"fork":false,"pushed_at":"2016-07-15T20:37:40.000Z","size":32,"stargazers_count":60,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T08:47:35.037Z","etag":null,"topics":[],"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/rightlag.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2016-01-14T17:49:41.000Z","updated_at":"2025-02-07T14:18:48.000Z","dependencies_parsed_at":"2023-03-07T03:45:16.567Z","dependency_job_id":null,"html_url":"https://github.com/rightlag/pyswagger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rightlag%2Fpyswagger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rightlag%2Fpyswagger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rightlag%2Fpyswagger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rightlag%2Fpyswagger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rightlag","download_url":"https://codeload.github.com/rightlag/pyswagger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578869,"owners_count":21127713,"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":[],"created_at":"2024-08-04T15:01:01.830Z","updated_at":"2025-04-12T14:08:59.480Z","avatar_url":"https://github.com/rightlag.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# pyswagger [![Build Status](https://img.shields.io/travis/rightlag/pyswagger/master.svg?style=flat-square)](https://travis-ci.org/rightlag/pyswagger) [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square)](https://gitter.im/rightlag/pyswagger)\n\npyswagger 0.2.0\n\nReleased: 7-Jan-2016\n\n# Release Notes\n\n  - **Release 0.2.0**\n    - Support for both token-based and HTTP basic authentication (e.g. `apiKey`, `basic`)\n    - Support for Swagger schema specifications to be read from hosted sites instead of reading them from local device\n    - Scheme is automatically assigned if not passed as an argument when issuing requests (e.g. `http`, `https`, `ws`, `wss`)\n    - Minor bug fixes\n\n  - **Release 0.1.0**\n    - Reads Swagger schema specifications\n    - Creates a `client` object used to instantiate requests to paths defined in the schema\n    - Supports `apiKey` authentication\n    - Supports common request methods (e.g. `GET`, `POST`, `PUT`, and `DELETE`)\n\n  - **Roadmap**\n    - `$ref` support\n    - Automatically determine MIME type for content-negotiation if not specified when issuing requests\n    - ~~Support for OAuth~~\n\n# Introduction\n\npyswagger is a Python toolkit that reads any JSON formatted [Swagger](http://swagger.io/) (Open API) schema and generates methods for the [operations](http://swagger.io/specification/#operationObject) defined in the schema.\n\n# Quickstart\n\nTo use the pyswagger client, import the `Swagger` class from the `swagger` module. The following example uses the [Swagger Petstore](http://petstore.swagger.io/) API.\n\n```python\n\u003e\u003e\u003e from swagger import Swagger\n\u003e\u003e\u003e client = Swagger.load('http://petstore.swagger.io/v2/swagger.json')\n\u003e\u003e\u003e res = client.get('/pet/findByStatus', status='sold')\n\u003e\u003e\u003e print res.json()\n[{u'category': {u'id': 1, u'name': u'Dogs'}, u'status': u'sold', u'name': u'Dog 2', u'tags': [{u'id': 1, u'name': u'tag2'}, {u'id': 2, u'name': u'tag3'}], u'photoUrls': [u'url1', u'url2'], u'id': 5}]\n```\n\nThis returns a list of `Pet` objects whose `status` attribute is assigned `sold`.\n\nThe `load()` method requires a URL to where the schema exists. The schema **must** be JSON formatted. In this example, the petstore schema is being loaded via a HTTP GET request and is then deserialized.\n\nThe `status` keyword argument is located within the list of parameters of the `/pet/findByStatus` path in the `petstore.json` schema.\n\n# Query parameters\n\nEndpoints that accept optional or required query parameters can be passed as keyword arguments to the method call.\n\n# Endpoints containing IDs\n\nFor endpoints that contain IDs (e.g. `/pet/2`), pyswagger uses string interpolation to match the ID with the respective keyword argument. The following example simulates a `GET` request that will return a pet with ID `2`:\n\n```python\nfrom swagger import Swagger\n\u003e\u003e\u003e client = Swagger.load('http://petstore.swagger.io/v2/swagger.json')\n\u003e\u003e\u003e res = client.get('/pet/{petId}', petId=2)\n\u003e\u003e\u003e print res.json()\n{u'category': {u'id': 2, u'name': u'Cats'}, u'status': u'available', u'name': u'Cat 2', u'tags': [{u'id': 1, u'name': u'tag2'}, {u'id': 2, u'name': u'tag3'}], u'photoUrls': [u'url1', u'url2'], u'id': 2}\n```\n\nThe `{petId}` placeholder is matched in the endpoint string and is replaced with the value of the `petId` keyword argument.\n\n# Requests containing a payload\n\nFor requests that require a request payload, the `body` keyword argument can be passed as an argument to the method. The value of the `body` argument *should* be [serialized](https://en.wikipedia.org/wiki/Serialization). The following example simulates a `POST` request that will create a new pet:\n\n```python\n\u003e\u003e\u003e import json\n\u003e\u003e\u003e from swagger import Swagger\n\u003e\u003e\u003e data = {\n...     'id': 0,\n...     'category': {\n...         'id': 0,\n...         'name': 'string',\n...     },\n...     'name': 'doggie',\n...     'photoUrls': [\n...         'string',\n...     ],\n...     'tags': [\n...         {\n...             'id': 0,\n...             'name': 'string',\n...         }\n...     ],\n...     'status': 'available',\n... }\n\u003e\u003e\u003e data = json.dumps(data)\n\u003e\u003e\u003e client = Swagger.load('http://petstore.swagger.io/v2/swagger.json')\n\u003e\u003e\u003e res = client.post('/pet', body=data, auth='special-key')\n\u003e\u003e\u003e print res.status_code, res.reason\n200 OK\n```\n\n**Note:** Some endpoints do not return a response body. Therefore, invoking the `.json()` method on the response object will raise an exception.\n\nThe example above  also includes the `auth` keyword argument which is explained in further detail in the next section.\n\n# Authenticated endpoints\n\nAuthentication is sometimes required to access some or all endpoints of a web API. Since pyswagger is a client-side toolkit, it does not support authentication schemes such as [OAuth](https://en.wikipedia.org/wiki/OAuth). However, if the endpoint requires an access token to make a request, then the `auth` keyword argument can be supplied.\n\n## Using the `auth` keyword argument\n\nSwagger uses [Security Definitions](http://swagger.io/specification/#securityDefinitionsObject) to define security schemes available to be used in the specification. For [token-based authentication](https://scotch.io/tutorials/the-ins-and-outs-of-token-based-authentication), The `in` field states the location of the API key which is either the `query` or the `header`. For [HTTP Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication), the `in` keyword is *not* defined.\n\nIf a token-based authentication security definition exists in the schema, pyswagger inspects the value of the `in` field and automatically assigns it as a request header or a query parameter. Therefore, when using the `auth` keyword, it is not required to specify the location of the API key.\n\n**Token authentication**\n\nTo use token authentication, the `auth` keyword argument *should* be of type `str`.\n\n```python\n\u003e\u003e\u003e from swagger import Swagger\n\u003e\u003e\u003e client = Swagger.load('http://petstore.swagger.io/v2/swagger.json')\n\u003e\u003e\u003e res = client.get('/pet/{petId}', petId=2, auth='special-token')\n```\n\n**HTTP basic authentication**\n\nTo use HTTP basic authentication, the `auth` keyword argument *should* be of type `tuple`.\n\n```python\n\u003e\u003e\u003e from swagger import Swagger\n\u003e\u003e\u003e client = Swagger.load('http://petstore.swagger.io/v2/swagger.json')\n\u003e\u003e\u003e res = client.get('/pet/{petId}', petId=2, auth=('username', 'password'))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightlag%2Fpyswagger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frightlag%2Fpyswagger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightlag%2Fpyswagger/lists"}