Easy API client generator
Project description
pyapiX
A tool for quickly creating high quality API clients (SDKs). Initial target APIs are those defined in Swagger/OpenAPI.
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 directory for more client definitions and the examples directory for usage examples.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyapix-2025.2.14.tar.gz.
File metadata
- Download URL: pyapix-2025.2.14.tar.gz
- Upload date:
- Size: 235.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8803bd461f3b5a012b3bd760f28a4bab6ab2f1165ed6dbacf8640365ef1d49fd
|
|
| MD5 |
8d50ff5c575f421ba8b4fff846aa792a
|
|
| BLAKE2b-256 |
38e42a9c0e4b5d17e710ba14119e00d1f88f5929ca3def6254ad7d831736e047
|
File details
Details for the file pyapix-2025.2.14-py3-none-any.whl.
File metadata
- Download URL: pyapix-2025.2.14-py3-none-any.whl
- Upload date:
- Size: 270.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b5f4e7070d7d50e81dd8960cd2c102699322f4e86a882673b193f0d684ca699
|
|
| MD5 |
44845954e31377d57d73530b339adc88
|
|
| BLAKE2b-256 |
1913e6f85939a8536d70e0e90ab0b5b7bebca526af6e86cdf79fc341581c9007
|