Skip to main content

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.


foo

Tuff 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 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

pyapix-2025.2.7.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyapix-2025.2.7-py3-none-any.whl (76.0 kB view details)

Uploaded Python 3

File details

Details for the file pyapix-2025.2.7.tar.gz.

File metadata

  • Download URL: pyapix-2025.2.7.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for pyapix-2025.2.7.tar.gz
Algorithm Hash digest
SHA256 f2703dc8380ecb5660b62c717b6a3b7bbde608210137d16e9e1c6c1ed98b8721
MD5 1bcf4273618304668df5f791f87d819b
BLAKE2b-256 f30b12541cfa5de41fe899163c525c13aaf1181349dbb44a25125b841ab8708d

See more details on using hashes here.

File details

Details for the file pyapix-2025.2.7-py3-none-any.whl.

File metadata

  • Download URL: pyapix-2025.2.7-py3-none-any.whl
  • Upload date:
  • Size: 76.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for pyapix-2025.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 362698ba36e0e281a076a3649777165c71c41ca7f973565786937c00154ccfb3
MD5 ab52da04acd4c3977caf9c056effa24c
BLAKE2b-256 8ee0f0173596549eb8e1aa17c25e02e9616ef3ed5f43dc0c63a7b08461c12b8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page