Skip to main content

The python framework, providing fast and robust way to build client-side API wrappers.

Project description

sensei

Logo Banner


PyPi Version PyPI Downloads License Last Commit Development Status

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 OOP style.

from typing import Annotated, Any, Self
from sensei import Router, Query, Path, APIModel, Header, Args, pascal_case, fill_path_params, RateLimit

router = Router('https://reqres.in/api', rate_limit=RateLimit(5, 1))


@router.model()
class BaseModel(APIModel):
    def __finalize_json__(self, json: dict[str, Any]) -> dict[str, Any]:
        return json['data']

    def __prepare_args__(self, args: Args) -> Args:
        args.headers['X-Token'] = 'secret_token'
        return args

    def __header_case__(self, s: str) -> str:
        return pascal_case(s)


class User(BaseModel):
    email: str
    id: int
    first_name: str
    last_name: str
    avatar: str

    @classmethod
    @router.get('/users')
    def query(
            cls,
            page: Annotated[int, Query(1)],
            per_page: Annotated[int, Query(3, le=7)],
            bearer_token: Annotated[str, Header('secret', le=10)],
    ) -> list[Self]:
        ...

    @classmethod
    @router.get('/users/{id_}')
    def get(cls, id_: Annotated[int, Path(alias='id')]) -> Self:
        ...

    @router.delete('/users/{id_}')
    def delete(self) -> Self:
        ...

    @delete.prepare
    def _delete_in(self, args: Args) -> Args:
        url = args.url
        url = fill_path_params(url, {'id_': self.id})
        args.url = url
        return args


users = User.query(per_page=7)
user_id = users[0].id
user = User.get(user_id)
print(user == users[0])

Example of functional style.

from typing import Annotated
from sensei import Router, Path, APIModel

router = Router('https://pokeapi.co/api/v2/')


class Pokemon(APIModel):
    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/CrocoFactory/sensei.git

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

sensei-0.1.0b3.post1.tar.gz (52.9 kB view details)

Uploaded Source

Built Distribution

sensei-0.1.0b3.post1-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file sensei-0.1.0b3.post1.tar.gz.

File metadata

  • Download URL: sensei-0.1.0b3.post1.tar.gz
  • Upload date:
  • Size: 52.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/24.0.0

File hashes

Hashes for sensei-0.1.0b3.post1.tar.gz
Algorithm Hash digest
SHA256 fe3e5b7a187bb37d864792750f92e82074c365ce9226fda7a9533cb0557c2019
MD5 7c1a61b1c19d1751a79e71cabcb4357c
BLAKE2b-256 8b7012411339b49603e17e2e8e64a914469bf0fce43bbc30580ace11107f7747

See more details on using hashes here.

File details

Details for the file sensei-0.1.0b3.post1-py3-none-any.whl.

File metadata

  • Download URL: sensei-0.1.0b3.post1-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/24.0.0

File hashes

Hashes for sensei-0.1.0b3.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b8926e3c5b165dad0418b2bea7a8bbcfccf04a04f8ab67f196e068612544a69
MD5 82179cb64641d2de21a916bbac880868
BLAKE2b-256 06d0864de197af60824cf18911c6d14baae78fc91ec1f318d9677776305fff29

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