Skip to main content

Python async OpenAPI client library

Project description

Lapidary

test

Python DSL for Web API clients.

http://lapidary.dev/

Why

DRY. Web API clients follow a relatively small set of patterns and writing them is rather repetitive task. Encoding these patterns in form of a DSL library frees its users from implementing the same patterns over and over again.

How

Lapidary is an internal DSL made of decorators and annotations, that can be used to describe Web APIs similarly to OpenAPI (lapidary-render can convert a large subset of OpenAPI 3.0 to Lapidary).

At runtime, the library interprets user-provided function declarations (without bodies), and makes them behave as declared. If a function accepts parameter of type X and returns Y, Lapidary will try to convert X to HTTP request and the response to Y.

Example:

class CatClient(ClientBase):
    """This class is a working API client"""

    def __init__(self):
        super().__init__(
            base_url='https://example.com/api',
        )

    @get('/cat')
    async def list_cats(self: Self) -> Annotated[
        tuple[list[Cat], CatListMeta],
        Responses({
            '2XX': Response(
                Body({
                    'application/json': list[Cat],
                }),
                CatListMeta
            ),
        })
    ]:
       pass

client = CatClient()
cats_body, cats_meta = await client.list_cats()

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

lapidary-0.12.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

lapidary-0.12.0-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file lapidary-0.12.0.tar.gz.

File metadata

  • Download URL: lapidary-0.12.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for lapidary-0.12.0.tar.gz
Algorithm Hash digest
SHA256 df9208082c24305b641a71a0ada8f4e28387429e98531ef8eec945c0817ef027
MD5 162b0cb26c99432f795dae96c76102db
BLAKE2b-256 b13d66eb4b2c315312dd6f16632ae39893f24f2b329381215a79fb7ad5c473f4

See more details on using hashes here.

File details

Details for the file lapidary-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: lapidary-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for lapidary-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a65afe9efc0016cc87d39783bc982f41321a78d64917d4c61a5b8ff5f79ee5c
MD5 d636763e0ab128fa2028d89834dbaa95
BLAKE2b-256 c8dd2bf6020e663c414a0c9349096f7f242f02fbf0d33cdca754ad0e564434a3

See more details on using hashes here.

Supported by

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