-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 Move documentation build to a separate repo.
- Loading branch information
Raphael Krupinski
committed
Jun 4, 2024
1 parent
9bb4a9d
commit 80a9175
Showing
8 changed files
with
82 additions
and
154 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,8 @@ | ||
[![test](https://github.com/python-lapidary/lapidary/actions/workflows/test.yaml/badge.svg)](https://github.com/python-lapidary/lapidary/actions/workflows/test.yaml) | ||
|
||
# Lapidary | ||
|
||
[![test](https://github.com/python-lapidary/lapidary/actions/workflows/test.yaml/badge.svg)](https://github.com/python-lapidary/lapidary/actions/workflows/test.yaml) | ||
|
||
Python DSL for Web API clients. | ||
|
||
Also check [lapidary-render](https://github.com/python-lapidary/lapidary-render/), | ||
a command line program that generates Lapidary clients from OpenAPI. | ||
|
||
## Features | ||
|
||
- [x] Write Web API clients declaratively | ||
- [x] Use pydantic models for JSON data | ||
- [ ] Compatibility with OpenAPI 3.0 and 3.1 | ||
|
||
## Installation | ||
|
||
```console | ||
pip install lapidary | ||
``` | ||
|
||
or with Poetry | ||
|
||
```console | ||
poetry add lapidary | ||
``` | ||
|
||
## Usage | ||
|
||
With Lapidary, you define an API client by creating a class that mirrors the API structure, akin to OpenAPI but through | ||
decorated and annotated Python methods. Calling these method handles making HTTP requests and transforming the responses | ||
back into Python objects. | ||
|
||
```python | ||
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) | ||
``` | ||
|
||
See [this test file](https://github.com/python-lapidary/lapidary/blob/develop/tests/test_client.py) for a working | ||
example. | ||
|
||
[Full documentation](https://lapidary.dev) | ||
|
||
Also check the [library of clients](https://github.com/orgs/lapidary-library/repositories). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,23 @@ | ||
site_name: Lapidary | ||
site_description: Build Web API clients with python annotations | ||
copyright: © 2024 Rafał Krupiński | ||
site_name: Lapidary runtime | ||
repo_url: https://github.com/python-lapidary/lapidary | ||
repo_name: python-lapidary/lapidary | ||
edit_uri: '' | ||
|
||
docs_dir: ../docs | ||
site_dir: ../site | ||
site_url: https://lapidary.dev/ | ||
|
||
nav: | ||
- Lapidary: index.md | ||
- index.md | ||
- Usage: | ||
- usage/client.md | ||
- usage/operation.md | ||
- usage/auth.md | ||
- Reference: | ||
- reference/lapidary.md | ||
|
||
plugins: | ||
- mkdocstrings: | ||
handlers: | ||
python: | ||
paths: | ||
- ../src | ||
- src | ||
options: | ||
docstring_style: sphinx | ||
|
||
theme: | ||
name: material | ||
logo: logo.svg | ||
favicon: logo.png | ||
language: en | ||
features: | ||
- navigation.instant | ||
- navigation.sections | ||
plugins: | ||
- privacy | ||
custom_dir: theme | ||
markdown_extensions: | ||
- admonition | ||
- tables | ||
- pymdownx.tasklist | ||
|
||
extra: | ||
analytics: | ||
provider: goatcounter | ||
code: lapidary |
2 changes: 0 additions & 2 deletions
2
config/theme/partials/integrations/analytics/goatcounter.html
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Lapidary | ||
|
||
Python DSL for Web API clients. | ||
|
||
## Features | ||
|
||
- [x] Write Web API clients declaratively | ||
- [x] Use pydantic models for JSON data | ||
- [ ] Compatibility with OpenAPI 3.0 and 3.1 | ||
|
||
## Installation | ||
|
||
```console | ||
pip install lapidary | ||
``` | ||
|
||
or with Poetry | ||
|
||
```console | ||
poetry add lapidary | ||
``` | ||
|
||
## Usage | ||
|
||
With Lapidary, you define an API client by creating a class that mirrors the API structure, akin to OpenAPI but through | ||
decorated and annotated Python methods. Calling these method handles making HTTP requests and transforming the responses | ||
back into Python objects. | ||
|
||
```python | ||
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) | ||
``` | ||
|
||
See [this test file](https://github.com/python-lapidary/lapidary/blob/develop/tests/test_client.py) for a working | ||
example. | ||
|
||
[Full documentation](https://lapidary.dev) | ||
|
||
Also check the [library of clients](https://github.com/orgs/lapidary-library/repositories). |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Lapidary Reference | ||
|
||
::: lapidary.runtime |