The python framework, providing fast and robust way to build client-side API wrappers.
Project description
sensei
The python framework, providing fast and robust way to build client-side API wrappers.
Source code is made available under the MIT License
Quick Overview
Here is example of code.
from typing import Annotated
from httpx import Response
from sensei import Router, Query, Path, BaseModel
router = Router('https://reqres.in/api')
class User(BaseModel):
email: str
id: int
first_name: str
last_name: str
avatar: str
@router.get('/users')
def get_users(
page: Annotated[int, Query(1)],
per_page: Annotated[int, Query(3, le=7)],
) -> list[User]:
...
@get_users.finalizer
def _get_users_out(
response: Response,
) -> list[User]:
json = response.json()
users = [User(**user) for user in json['data']]
return users
@router.get('/users/{id_}')
def get_user(id_: Annotated[int, Path(alias='id')]) -> User:
...
@get_user.finalizer
def _get_user_out(response: Response) -> User:
json = response.json()
return User(**json['data'])
users = get_users(per_page=7)
user_id = users[1].id
user = get_user(user_id)
print(user == users[1])
Another example
from typing import Annotated
from sensei import Router, Path, BaseModel
router = Router('https://pokeapi.co/api/v2/')
class Pokemon(BaseModel):
name: str
id: int
height: int
weight: int
types: list
@router.get('/pokemon/{pokemon_name}')
def get_pokemon(
pokemon_name: Annotated[str, Path()],
) -> Pokemon:
...
pokemon = get_pokemon(pokemon_name="pikachu")
print(pokemon)
Installing sensei
To install sensei
from PyPi, you can use that:
pip install sensei
To install sensei
from GitHub, use that:
pip install git+https://github.com/blnkoff/sensei.git
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sensei-0.1.0a1.tar.gz
(15.3 kB
view details)
Built Distribution
sensei-0.1.0a1-py3-none-any.whl
(19.8 kB
view details)
File details
Details for the file sensei-0.1.0a1.tar.gz
.
File metadata
- Download URL: sensei-0.1.0a1.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3813786e8897ed01efcce6f2b5838cf595d83c435fcd4a07791931c72f27587 |
|
MD5 | 40234e8a32803b22510ca20cdb51c6e9 |
|
BLAKE2b-256 | e06e04dac4aa7c593753450c6d019427ba2279cb14adda896aa48603a6666ef1 |
File details
Details for the file sensei-0.1.0a1-py3-none-any.whl
.
File metadata
- Download URL: sensei-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c7712072051e3b47d1e292ca805b98f79969ad439f5d496f60539d11ec5804d |
|
MD5 | c7d915c06b763b50ee4dce9e0e42ada1 |
|
BLAKE2b-256 | bd8c55adde4bcf570ad7a267b0d60490756358e52df7f84d8919be9da48912d7 |