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.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

lapidary-0.12.2-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lapidary-0.12.2.tar.gz
  • Upload date:
  • Size: 15.4 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.2.tar.gz
Algorithm Hash digest
SHA256 72d5ac50a475eedc3c5d897663ae1d9ad10f4885f3724319c213503d7bffbaec
MD5 65f2a8aa76c73bba6f4d765463dee2e5
BLAKE2b-256 a4a06c21bf774d59d3329ad3129435a0bb11568e3356b14613203366a86c29d0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lapidary-0.12.2-py3-none-any.whl
  • Upload date:
  • Size: 21.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 48dce73b36b953ae1f6491165943cfefb69459883a34f03204ce21a09cbcb6c2
MD5 0352eaf6409289647002e1b25d179277
BLAKE2b-256 103637a8f54d415f966ff330b7e2b1c34079a1afc0189e516c6d1de7e188bdb3

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