Skip to content

jj136975/SimpleSDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleSDK

A lightweight async Python framework for building type-safe REST API clients, built on aiohttp and pyserde.

Features

  • Async HTTP client with automatic retry and exponential backoff
  • Type-safe JSON serialization via pyserde
  • Pluggable authentication (token-based auth included)
  • Custom error models per API
  • Configurable timeouts, headers, and user-agent

Installation

Requires Python 3.12+.

pip install simple_sdk

Quick Start

Define your models, API, and client:

from serde import serde
from aiohttp import ClientSession
from simple_sdk import BaseApi, JsonApiClient, BaseConfiguration, TokenAuthenticator, CredentialLoader


# Models
@serde
class Profile:
    id: int
    name: str


# API
class MyApi(BaseApi):
    def __init__(self, session: ClientSession) -> None:
        super().__init__(session)

    async def get_profile(self) -> Profile:
        return await self.get("/profile", model=Profile)


# Client
class MyClient(JsonApiClient):
    def __init__(self, config: BaseConfiguration, auth: TokenAuthenticator) -> None:
        super().__init__(config, auth)
        self._my_api: MyApi | None = None

    @property
    def my_api(self) -> MyApi:
        if self._my_api is None:
            self._my_api = MyApi(self._session)
        return self._my_api

Then use it:

import asyncio
from simple_sdk import BaseConfiguration


async def main():
    config = BaseConfiguration(base_url="http://localhost:8080")

    async with MyClient(config, auth=...) as client:
        profile = await client.my_api.get_profile()
        print(profile)


asyncio.run(main())

License

This project is licensed under the MIT License.

About

A basic, lightweight and generic SDK for multi-purpose APIs. Focused on performances and low consumption to run in Cloud Compute units (AWS Lambda, Cloud Run, ...)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages