Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manchenkoff/openapi3-parser
OpenAPI 3 parser to use a specification inside of the code in your projects
https://github.com/manchenkoff/openapi3-parser
openapi openapi-specification openapi3 parser python3 swagger
Last synced: 4 days ago
JSON representation
OpenAPI 3 parser to use a specification inside of the code in your projects
- Host: GitHub
- URL: https://github.com/manchenkoff/openapi3-parser
- Owner: manchenkoff
- License: mit
- Created: 2020-08-27T00:47:00.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-28T14:30:25.000Z (about 2 months ago)
- Last Synced: 2024-12-15T22:05:51.181Z (11 days ago)
- Topics: openapi, openapi-specification, openapi3, parser, python3, swagger
- Language: Python
- Homepage: https://pypi.org/project/openapi3-parser/
- Size: 288 KB
- Stars: 67
- Watchers: 3
- Forks: 34
- Open Issues: 20
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: license.txt
- Security: SECURITY.md
Awesome Lists containing this project
README
# 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.
Supported versions:
| Version | Status |
| ------- | -------------- |
| 2.0 | Deprecated |
| 3.0 | **Supported** |
| 3.1 | In development |## 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 parsespecification = 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 parsespecification = 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 parsespecification = 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
```