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/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.0b2.tar.gz (44.1 kB view details)

Uploaded Source

Built Distribution

sensei-0.1.0b2-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sensei-0.1.0b2.tar.gz
  • Upload date:
  • Size: 44.1 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.0b2.tar.gz
Algorithm Hash digest
SHA256 1819b7fa1abb00bd6d1fad52339bea0ed45d2ad3ce347dcb48f95510052e73cb
MD5 c8ade8974770c6f532440f345e30ddbd
BLAKE2b-256 56741b2a1319b24828d9786472322634b0a362818cd744f9e4567abefa822fac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sensei-0.1.0b2-py3-none-any.whl
  • Upload date:
  • Size: 22.3 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.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 c51c5e4d0798a859e525da01ad7d3e35c705d5c5d2b97ffbb37e57752c16ba8d
MD5 9fa35123e94ee0e96c97b6d5272c1bbf
BLAKE2b-256 daebe829ad16093bf317edb2c2e7b16c7a70f0a67787bff493689b9965c8d669

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