Skip to content

Releases: python-lapidary/lapidary

v0.12.0

21 Oct 14:49
Compare
Choose a tag to compare

This release adds iter_pages helper function for iterating over paged resources, and support for middleware which can modify httpx requests and responses on the fly.

See the change log.

0.11.0

17 Aug 12:47
Compare
Choose a tag to compare

This release introduces some fundamental new features:

  • thanks to pydantic, operation function arguments and response headers accept non-primitive types
  • error responses and undeclared responses raise exceptions. If the response is in the response map, it's processed like a normal response and wrapped in an exception, otherwise exception includes the original httpx.Response
  • responses are now declared as tuple[BodyModel, HeadresModel]. Operation functions are now written this way:
@get('/')
async def get(...)->Annotated[
  tuple[ResponseBody, ResponseHeaders],
  Responses({
    'default': Response(
      Body({'application/json': list[Cat]}),
      CatListResponseHeaders
    )
  }),
]:
  ...

Also, input parameters can be wrapped in a model, which allows this style:

response_body, response_headers = await client.get(body=request_body, headers=request_headers)

v0.10.0

02 Jun 22:28
Compare
Choose a tag to compare

From now on you can use ResponseEnvelope type to wrap response body and any headers you want to receive from the server.

class CatListResponse(ResponseEnvelope):
    body: typing.Annotated[typing.List[Cat], ResponseBody]
    count: typing.Annotated[int, Header('X-Count')]


class CatClient(ClientBase):
    @get('/cats')
    async def cat_list(
        self: typing.Self,
    ) -> typing.Annotated[
        CatListResponse,
        Responses({
            'default': {'application/json': CatListResponse},
        }),
    ]:
        pass

0.9.1

25 May 16:17
Compare
Choose a tag to compare

Move pytest-asyncio dependency to dev group.

0.9.0

17 May 07:32
Compare
Choose a tag to compare

Lapidary 0.9.0 is pretty much a new library.
Now it's more of a DSL capable of describing a Web API in a manner similar to OpenAPI 3.0,

from typing import Annotated, Self
from lapidary.runtime import *

# Define models

class Cat(ModelBase):
    id: int
    name: str

# Declare the client

class CatClient(ClientBase):
    def __init__(
        self,
        base_url='http://localhost:8080/api',
    ):
        super().__init__(base_url=base_url)

    @get('/cat/{id}')
    async def cat_get(
        self: Self,
        *,
        id: Annotated[int, Path(style=ParamStyle.simple)],
    ) -> Annotated[Cat, Responses({
        '2XX': {
            'application/json': Cat
        },
    })]:
        pass

# User code

async def main():
    client = CatClient()
    cat = await client.cat_get(id=7)