Skip to main content

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

Project description

sensei

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
from httpx import Response
from sensei import Router, Query, Path, APIModel

router = Router('https://reqres.in/api')


class User(APIModel):
    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)],
    ) -> list["User"]:
        ...

    @staticmethod
    @query.finalizer()
    def _query_out(
            response: Response,
    ) -> list["User"]:
        json = response.json()
        users = [User(**user) for user in json['data']]
        return users

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

    @staticmethod
    @get.finalizer
    def _get_out(response: Response) -> "User":
        json = response.json()
        return User(**json['data'])


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/blnkoff/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.0b1.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

sensei-0.1.0b1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file sensei-0.1.0b1.tar.gz.

File metadata

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

File hashes

Hashes for sensei-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 42ea73fcb475a7ac4b06b632628f35c4bd0b6261122ea3df4e63342d7a7f1d9a
MD5 dbd744699262f5f0e10c18815ec43262
BLAKE2b-256 5e3a835a3a0da90a51615845a29f00efbc5c6ab886b57fcc30f3be6ee7d27045

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sensei-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 21.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

Hashes for sensei-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 dde78fce718ddd2b263a352a04e60bbca0572cec85440cc83c464ca8df12c9e4
MD5 1ebfd12a497cebd8d8b5ef96a4a33c56
BLAKE2b-256 e415dbb2a307d7c045e3f8f6b230242850cfb8da5bae57ec99a439bb628b21b8

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