Skip to main content

Python API client generator

Project description

Lapis - Python OpenAPI client generator

Generate OpenAPI 3.0.3 client code that is easy to understand and debug.

Leverages Pydantic as the base classes and httpx as the HTTP client.

Usage

lapis [--errata path] spec_file target_dir root_package

Lapis will create target_dir, all necessary directories and pyproject.toml if they don't exist.

Generated files will be placed in <target_dir>/gen/<root_package>

Errata is a JSON Patch file in JSON or YAML format; it's applied to the spec before any other processing.

Supported OpenAPI features

  • Parameter names: operation parameters are uniquely identified by their name the value of an in attribute. It is possible to have parameter named param in all of path, query, cookies and headers.

    Lapis uses Hungarian notation for method parameter names.

  • Enums: [TODO] there's no limitation that enum schema cannot be an object or an array.

    Enums might need two python classes - a subclass of enum.Enum and the schema class.

  • oneOf: maps to typing.Union

  • AllOf: [TODO] maps to a separate class that uses all the schemas as superclasses.

  • AnyOf: [TODO] maps to similar class as in case of AllOf, all fields should be non-required and the object should validate against at least one of superclasses.

  • Recursive references between schemas: supported.

  • References to other schemas: unsupported.

  • Read- and write-only attributes: [TODO] Read-only attributes are considered non-existent when the object is validated before being sent to the server.

Broken and incomplete API specifications

  • errata: use errata to update the specification document in cases where actual data doesn't match it, and the service provider is reluctant or slow to update it.

TODO: pre- and postprocessing of API specification (dict- and pydantic-based models) with python code, errata (jsonpatch), etc

Backwards compatibility

Once stable, Lapis should generate code that is backwards compatible as long as the API specification is too. The following rules are used to ensure that.

Names of interface elements (public functions, classes and methods) are fully deterministic and are derived only from their source elements and, in some cases, their parents. For example, schemas of the same name are either placed in separate modules, or their names have the parent element name prepended.

Each operation must have operationId which is used to create a unique package for its models.

The structure of the API specification is roughly reflected in the generated code. Each schema under #/components/schemas together with all inline parameter schemas will become a single module in <your_package>.components.schemas. Each operation must define operationId which will be used as a sub-package name for the module containing its all inline schemas. Operation packages will be placed under <your_package>.paths

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

lapis-gen-0.3.1.tar.gz (57.0 kB view details)

Uploaded Source

Built Distribution

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

lapis_gen-0.3.1-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file lapis-gen-0.3.1.tar.gz.

File metadata

  • Download URL: lapis-gen-0.3.1.tar.gz
  • Upload date:
  • Size: 57.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Darwin/21.6.0

File hashes

Hashes for lapis-gen-0.3.1.tar.gz
Algorithm Hash digest
SHA256 b4870d4c35ebc6365db270e185e2b4b5277275e1802f7e54ac1d73b07049499c
MD5 06192a9d40cebcd263d870203611c351
BLAKE2b-256 d9bbd3d55cba8f8276dff2a84340432c06b4367e0d63e4b90b9f92c4db9b8ab8

See more details on using hashes here.

File details

Details for the file lapis_gen-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: lapis_gen-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.6 Darwin/21.6.0

File hashes

Hashes for lapis_gen-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33d0b68ed3ad3a4fc7a73fe7a51abec4738c06bde3fd7a98228566f9285fd317
MD5 bd5c8fc2ee5a5b9433ad8021e159e42b
BLAKE2b-256 4329e1c93f5df46c5bb9b4300828fe24bc09751276dd0739c00733af00db438e

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