# pyapiX
A tool for quickly creating high quality API clients (SDKs). Initial target APIs are
those defined in Swagger/OpenAPI.
----------------


[](https://github.com/astral-sh/ruff)
## Installation
Available on PyPI.
uv pip install pyapix
or
pip install pyapix
# How to use it
If you are familiar with the SwaggerDoc for an API or a Postman collection, the
client will look familiar. Many of your intuitions from SwaggerDoc or Postman
will help you in working with the client.
# WoRMS: World Register of Marine Species
from pyapix.apis.worms import _validator, call
(endpoint, verb) = '/AphiaClassificationByAphiaID/{ID}', 'get'
validator = _validator(endpoint, verb)
parameters = {'ID': 127160 }
assert validator.is_valid(parameters)
response = call(endpoint, verb, parameters)
assert response.status_code == 200
(endpoint, verb) = '/AphiaRecordsByName/{ScientificName}', 'get'
validator = _validator(endpoint, verb)
parameters = {'ScientificName': 'Solea solea' }
assert validator.is_valid(parameters)
response = call(endpoint, verb, parameters)
rj = response.json()[0]
assert rj['kingdom'] == 'Animalia'
assert rj['authority'] == '(Linnaeus, 1758)'
parameters = {'foo': 'Solea solea' }
validator.validate(parameters)
Traceback (most recent call last):
...
jsonschema.exceptions.ValidationError: 'ScientificName' is a required property
Failed validating 'required' in schema:
{'required': ['ScientificName'],
'properties': {'ScientificName': {'type': 'string'},
'like': {'type': 'boolean', 'default': 'true'},
'marine_only': {'type': 'boolean', 'default': 'true'},
'offset': {'type': 'integer', 'default': 1}},
'additionalProperties': False,
'type': 'object'}
On instance:
{'foo': 'Solea solea'}
# API-client definition
# WoRMS: World Register of Marine Species
from pyapix.apis.api_tools import dynamic_validator, dynamic_call
class config:
swagger_path = 'https://www.marinespecies.org/rest/api-docs/openapi.yaml'
api_base = 'https://www.marinespecies.org/rest'
alt_swagger = lambda x: x
head_func = lambda endpoint, verb: {}
validate = lambda params: None
_validator = dynamic_validator(config)
call = dynamic_call(config)
The client definition is about 15 lines. Most APIs require more but never over 100
lines. More complex APIs benefit more from this approach. This approach eliminates
the manual effort of object definitions required by a DAO-based approach while
more accurately representing the contents of the OpenAPI file. It also
eliminates the need for manual documentation by leveraging work
already done by the OpenAPI author. https://www.marinespecies.org/rest/
See the [apis](apis) directory for more client definitions and the
[examples](examples) directory for usage examples.
Raw data
{
"_id": null,
"home_page": null,
"name": "pyapiX",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "API, OpenAPI, REST, functional, swagger",
"author": null,
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/44/b4/b7636f2ee154504ae5ceef262ad659dcefa3768523b6cdbae146398b1e9a/pyapix-2025.2.2.tar.gz",
"platform": null,
"description": "\n# pyapiX\n\n\nA tool for quickly creating high quality API clients (SDKs). Initial target APIs are\nthose defined in Swagger/OpenAPI.\n\n----------------\n\n\n\n\n[](https://github.com/astral-sh/ruff)\n\n## Installation\n\nAvailable on PyPI.\n\n\n uv pip install pyapix\n or\n pip install pyapix\n\n\n\n# How to use it\n\nIf you are familiar with the SwaggerDoc for an API or a Postman collection, the\nclient will look familiar. Many of your intuitions from SwaggerDoc or Postman\nwill help you in working with the client.\n\n # WoRMS: World Register of Marine Species\n from pyapix.apis.worms import _validator, call\n\n (endpoint, verb) = '/AphiaClassificationByAphiaID/{ID}', 'get'\n validator = _validator(endpoint, verb)\n parameters = {'ID': 127160 }\n assert validator.is_valid(parameters)\n response = call(endpoint, verb, parameters)\n assert response.status_code == 200\n\n (endpoint, verb) = '/AphiaRecordsByName/{ScientificName}', 'get'\n validator = _validator(endpoint, verb)\n parameters = {'ScientificName': 'Solea solea' }\n assert validator.is_valid(parameters)\n response = call(endpoint, verb, parameters)\n rj = response.json()[0]\n assert rj['kingdom'] == 'Animalia'\n assert rj['authority'] == '(Linnaeus, 1758)'\n\n parameters = {'foo': 'Solea solea' }\n validator.validate(parameters)\n\n Traceback (most recent call last):\n ...\n jsonschema.exceptions.ValidationError: 'ScientificName' is a required property\n\n Failed validating 'required' in schema:\n {'required': ['ScientificName'],\n 'properties': {'ScientificName': {'type': 'string'},\n 'like': {'type': 'boolean', 'default': 'true'},\n 'marine_only': {'type': 'boolean', 'default': 'true'},\n 'offset': {'type': 'integer', 'default': 1}},\n 'additionalProperties': False,\n 'type': 'object'}\n\n On instance:\n {'foo': 'Solea solea'}\n\n\n# API-client definition\n\n # WoRMS: World Register of Marine Species\n\n from pyapix.apis.api_tools import dynamic_validator, dynamic_call\n\n\n class config:\n swagger_path = 'https://www.marinespecies.org/rest/api-docs/openapi.yaml'\n api_base = 'https://www.marinespecies.org/rest'\n alt_swagger = lambda x: x \n head_func = lambda endpoint, verb: {}\n validate = lambda params: None\n\n\n _validator = dynamic_validator(config)\n call = dynamic_call(config)\n\nThe client definition is about 15 lines. Most APIs require more but never over 100\nlines. More complex APIs benefit more from this approach. This approach eliminates\nthe manual effort of object definitions required by a DAO-based approach while\nmore accurately representing the contents of the OpenAPI file. It also\neliminates the need for manual documentation by leveraging work\nalready done by the OpenAPI author. https://www.marinespecies.org/rest/\n\nSee the [apis](apis) directory for more client definitions and the\n[examples](examples) directory for usage examples.\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Easy API client generator",
"version": "2025.2.2",
"project_urls": null,
"split_keywords": [
"api",
" openapi",
" rest",
" functional",
" swagger"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "79822c0541cac27a1ea1d243d732de096e7170a79a842ed8f608b2e265acd744",
"md5": "7c8ba3081a1c7589633e762e1dd6baeb",
"sha256": "077b12532ad001c37733038859546d08c68fdd98c880d9cf87a6bc432caaf691"
},
"downloads": -1,
"filename": "pyapix-2025.2.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7c8ba3081a1c7589633e762e1dd6baeb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 62892,
"upload_time": "2025-02-08T17:33:03",
"upload_time_iso_8601": "2025-02-08T17:33:03.470781Z",
"url": "https://files.pythonhosted.org/packages/79/82/2c0541cac27a1ea1d243d732de096e7170a79a842ed8f608b2e265acd744/pyapix-2025.2.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "44b4b7636f2ee154504ae5ceef262ad659dcefa3768523b6cdbae146398b1e9a",
"md5": "a4c727366712e0496aa9a3305d2713af",
"sha256": "8b07417c76ea5a4d4ac659523e2b4da9c88eee9a4df038d78852dac205c68069"
},
"downloads": -1,
"filename": "pyapix-2025.2.2.tar.gz",
"has_sig": false,
"md5_digest": "a4c727366712e0496aa9a3305d2713af",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 27219,
"upload_time": "2025-02-08T17:33:05",
"upload_time_iso_8601": "2025-02-08T17:33:05.212922Z",
"url": "https://files.pythonhosted.org/packages/44/b4/b7636f2ee154504ae5ceef262ad659dcefa3768523b6cdbae146398b1e9a/pyapix-2025.2.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-08 17:33:05",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "pyapix"
}