# OpenAPI Parser
![PyPI - Version](https://img.shields.io/pypi/v/openapi3-parser)
![PyPI - Downloads](https://img.shields.io/pypi/dm/openapi3-parser)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/openapi3-parser)
![PyPI - Format](https://img.shields.io/pypi/format/openapi3-parser)
![PyPI - License](https://img.shields.io/pypi/l/openapi3-parser)
A simple package to parse your OpenAPI 3 documents into Python object to work with.
## How to install
To install package run the following command
```
pip install openapi3-parser
```
## How to use
Example of parser usage
```
>>> from openapi_parser import parse
>>> content = parse('swagger.yml')
>>> print(content)
```
Get application servers
```python
from openapi_parser import parse
specification = parse('data/swagger.yml')
print("Application servers")
for server in specification.servers:
print(f"{server.description} - {server.url}")
# Output
#
# >> Application servers
# >> production - https://users.app
# >> staging - http://stage.users.app
# >> development - http://users.local
```
Get list of application URLs
```python
from openapi_parser import parse
specification = parse('tests/data/swagger.yml')
urls = [x.url for x in specification.paths]
print(urls)
# Output
#
# >> ['/users', '/users/{uuid}']
```
Get operation with supported HTTP methods
```python
from openapi_parser import parse
specification = parse('tests/data/swagger.yml')
for path in specification.paths:
supported_methods = ','.join([x.method.value for x in path.operations])
print(f"Operation: {path.url}, methods: {supported_methods}")
# Output
#
# >> Operation: /users, methods: get,post
# >> Operation: /users/{uuid}, methods: get,put
```
Raw data
{
"_id": null,
"home_page": "https://github.com/MrAdhit/openapi3-parser",
"name": "openapi3-parser-x",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "swagger,python,swagger-parser,openapi3-parser-x,parser,openapi3,swagger-api",
"author": "MrAdhit",
"author_email": "mradhit@kingland.id",
"download_url": "https://files.pythonhosted.org/packages/14/c4/08ab141f9cc7ae81e4987ab2c0596995c2db674275e4f920d6a6694321d1/openapi3-parser-x-1.1.22.tar.gz",
"platform": null,
"description": "# OpenAPI Parser\r\n\r\n![PyPI - Version](https://img.shields.io/pypi/v/openapi3-parser)\r\n![PyPI - Downloads](https://img.shields.io/pypi/dm/openapi3-parser)\r\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/openapi3-parser)\r\n![PyPI - Format](https://img.shields.io/pypi/format/openapi3-parser)\r\n![PyPI - License](https://img.shields.io/pypi/l/openapi3-parser)\r\n\r\nA simple package to parse your OpenAPI 3 documents into Python object to work with.\r\n\r\n## How to install\r\n\r\nTo install package run the following command\r\n\r\n```\r\npip install openapi3-parser\r\n```\r\n\r\n## How to use\r\n\r\nExample of parser usage\r\n\r\n```\r\n>>> from openapi_parser import parse\r\n>>> content = parse('swagger.yml')\r\n>>> print(content)\r\n```\r\n\r\nGet application servers\r\n\r\n```python\r\nfrom openapi_parser import parse\r\n\r\nspecification = parse('data/swagger.yml')\r\n\r\nprint(\"Application servers\")\r\n\r\nfor server in specification.servers:\r\n print(f\"{server.description} - {server.url}\")\r\n\r\n# Output\r\n#\r\n# >> Application servers\r\n# >> production - https://users.app\r\n# >> staging - http://stage.users.app\r\n# >> development - http://users.local\r\n```\r\n\r\nGet list of application URLs\r\n\r\n```python\r\nfrom openapi_parser import parse\r\n\r\nspecification = parse('tests/data/swagger.yml')\r\n\r\nurls = [x.url for x in specification.paths]\r\n\r\nprint(urls)\r\n\r\n# Output\r\n#\r\n# >> ['/users', '/users/{uuid}']\r\n```\r\n\r\nGet operation with supported HTTP methods\r\n\r\n```python\r\nfrom openapi_parser import parse\r\n\r\nspecification = parse('tests/data/swagger.yml')\r\n\r\nfor path in specification.paths:\r\n supported_methods = ','.join([x.method.value for x in path.operations])\r\n\r\n print(f\"Operation: {path.url}, methods: {supported_methods}\")\r\n\r\n# Output\r\n#\r\n# >> Operation: /users, methods: get,post\r\n# >> Operation: /users/{uuid}, methods: get,put\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "OpenAPI v3 parser",
"version": "1.1.22",
"project_urls": {
"Homepage": "https://github.com/MrAdhit/openapi3-parser",
"Source": "https://github.com/MrAdhit/openapi3-parser"
},
"split_keywords": [
"swagger",
"python",
"swagger-parser",
"openapi3-parser-x",
"parser",
"openapi3",
"swagger-api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "14c408ab141f9cc7ae81e4987ab2c0596995c2db674275e4f920d6a6694321d1",
"md5": "4c9cd274c7ad168cdfe7b9ad2ccaf1c2",
"sha256": "d2f3e62100bc437d0a1fe2f066b9b23739931c5c6768074ddccbed5309650db0"
},
"downloads": -1,
"filename": "openapi3-parser-x-1.1.22.tar.gz",
"has_sig": false,
"md5_digest": "4c9cd274c7ad168cdfe7b9ad2ccaf1c2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13483,
"upload_time": "2024-01-04T10:51:06",
"upload_time_iso_8601": "2024-01-04T10:51:06.979940Z",
"url": "https://files.pythonhosted.org/packages/14/c4/08ab141f9cc7ae81e4987ab2c0596995c2db674275e4f920d6a6694321d1/openapi3-parser-x-1.1.22.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-04 10:51:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MrAdhit",
"github_project": "openapi3-parser",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "openapi3-parser-x"
}