Skip to main content

An asynchronous Python API client for LANraragi, written with aiohttp and pydantic for type validation.

Project description

aio-lanraragi

An asynchronous Python API client for LANraragi, written with aiohttp and pydantic for type validation. The project is a work in progress.

pip install aio-lanraragi

A working understanding of Python's async framework is needed.

Usage

Here is an example on getting all archives from LANraragi using LRRClient's context management:

import asyncio
from lanraragi.clients.client import LRRClient

async def main():
    await with LRRClient("http://localhost:3000", lrr_api_key="lanraragi") as lrr:
        response = await lrr.archive_api.get_all_archives()
        print(response)

if __name__ == "__main__":
    asyncio.run(main())

Here is a code snippet on making concurrent API calls under a bounded semaphore.

...
async with LRRClient("http://localhost:3000", lrr_api_key="lanraragi") as lrr:
    semaphore = asyncio.BoundedSemaphore(value=4)
    tasks = []
    for req in requests:
        tasks.append(asyncio.create_task(async_task(lrr, req, semaphore)))
    await asyncio.gather(*tasks)

Development

pip install "aio-lanraragi[dev]"

Only documented APIs will be supported. Undocumented API calls may be invoked at the ApiContextManager layer by library users.

Library Description

All request/response classes are under the "src/lanraragi/models" directory, and inherit the LanraragiRequest and LanraragiResponse base class, respectively.

The ApiContextManager is an asynchronous HTTP context manager and handle the HTTP interaction with LANraragi.

If you don't want to use request/response DTOs, go with the API context manager.

An ApiClient represents a logical client for a collection of related APIs. They handle the DTO layer. These are only to be used by the LRRClient.

The LRRClient is a higher abstraction than ApiContextManager which also provides API clients for easy access in a context.

Scope

"aio-lanraragi" is designed to abstract away the boilerplate of interfacing with a LANraragi server in Python, to allow the user to focus on application business logic, rather than the HTTP/API protocols. This includes:

  • automatically choosing the REST method and parameters for the API
  • conversion between request, response and Pydantic DTOs for each API call
  • comfortable type hinting and rigorous request/response validation with Pydantic
  • aiohttp exception retry with exponential backoff
  • session management logic and implementation abstraction

The scope of this library is to implement LANraragi-related API functionality which comes naturally from supporting dependencies like aiohttp/pydantic, such as session-related functionality, or type validation. On the other hand, derivative features (features which can be implemented simply by invoking multiple APIs, sometimes with the help of additional dependencies) are not supported by aio-lanraragi. Derivative features include:

  • get version of server
  • delete all archives by a tag or pattern
  • upload archives from a folder
  • checking if an image is incomplete by reading file bytes

In other words, scripting does not fall under the library's responsibility.

Until a feasable client-server version-handling strategy is implemented, support for only the most current API specification falls under the scope of the project. Request/response changes across version updates, bug fixes, corrections, tests, and slight code practice alignments also fall within the scope of this project.

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

aio_lanraragi-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aio_lanraragi-0.1.0-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file aio_lanraragi-0.1.0.tar.gz.

File metadata

  • Download URL: aio_lanraragi-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for aio_lanraragi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd490fc7d50197cd436afcf7c04e16d641d7083839d25d49b5c984fce1bb2f32
MD5 55a7f21b821e95e915861d533d92b792
BLAKE2b-256 f5f94dcc9136317c20dbd2a7d0c8a567f335b8bd481311546931cdee2dce635f

See more details on using hashes here.

File details

Details for the file aio_lanraragi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aio_lanraragi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for aio_lanraragi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2b26e9f15a2a1b171df82d4e33bf7cf311a23352c0fda9f12a1bb835fbc2283
MD5 aacd57f8e7b738f8c64e5bf1223c0442
BLAKE2b-256 b154db624aa3c33567f65c87e013084adc4f8308bd15d9a77e8f25e4253e339d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page