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.21.tar.gz (802.6 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.21-py3-none-any.whl (847.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyapix-2025.2.21.tar.gz
  • Upload date:
  • Size: 802.6 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.21.tar.gz
Algorithm Hash digest
SHA256 03d93353a6d2cca7d245d4596324e9c9f772d6ff9f03e962b7937325e829f938
MD5 3826892fd61aae7d95457ed918a88784
BLAKE2b-256 0326e65b3e9fddd2cf8c2db6e2e8a1de6e6fe299794fa5de0733d06dec5e9341

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyapix-2025.2.21-py3-none-any.whl
  • Upload date:
  • Size: 847.8 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.21-py3-none-any.whl
Algorithm Hash digest
SHA256 e4f33f8afd2f67af741406a21b4d2f020a5401e58463afa190122a48abf01098
MD5 5e05eaf7589a6e0f8fb37c6026fc30df
BLAKE2b-256 17448eb620a38aed265712570055c69875b0a73b80da576500a9c9d0186f884d

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