Skip to content

Latest commit

 

History

History
61 lines (38 loc) · 1.55 KB

README.md

File metadata and controls

61 lines (38 loc) · 1.55 KB

api-lib Format and tests cov

A lightweight Python library for building and consuming APIs with ease.

Features

  • Simple API client utilities
  • Built-in request/response handling
  • Extensible and easy to integrate

Installation

It's recommended to use uv to install the package:

uv add api-lib

Usage

Example: Consuming an API

from api_lib import ApiLib
from api_lib.headers.accept import AcceptGithub
from api_lib.headers.authorization import Bearer
from api_lib.method import Method
from api_lib.objects.response import APIfield, APIobject, JsonResponse


@APIobject
class User(JsonResponse):
    login: str = APIfield()
    name: str = APIfield()
    disk_usage: int = APIfield()
    disk_space_limit: int = APIfield("plan/space")


class GithubAPI(ApiLib):
    headers = [AcceptGithub()]

    async def user(self) -> User:
        return await self.req(Method.GET, "/user", User)


api = GithubAPI("https://api.github.com", Bearer(env_var="GITHUB_TOKEN"))

user = await gh_api.user()

Documentation

See the full documentation for more details and advanced usage.

Contributing

Contributions are welcome! Please open issues or submit pull requests.

License

This project is licensed under the MIT License.