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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: lapidary-0.12.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b093b92c5646b4d2856de7dccdd3231e7965b344b226b8cc837774772d8f686d
MD5 59f769ab6bc88c14c92c918bc4d999b2
BLAKE2b-256 9d4364e3ab2ac233bcbaf00bee65e262cb047134671057f25c8b299124a537ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lapidary-0.12.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f7d45c984acc01c1efd4af2c5bc13292d87b915cbcf93918a8813ca0ccaee0a
MD5 4d119d8ea866be6bf5a67d3fb0245e20
BLAKE2b-256 3b4bb7293f18b37a8c32df8027ce7f41a1c77b92bdf9ef1579f533e93619cb66

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