Releases: python-lapidary/lapidary
Releases · python-lapidary/lapidary
v0.12.0
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
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
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
Move pytest-asyncio dependency to dev group.
0.9.0
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)