Skip to main content

Add your description here

Project description

AsyncToolkit

AsyncToolkit is a lightweight, extensible framework for building and running asynchronous tools in Python. It provides a unified interface for executing asynchronous operations, such as HTTP requests and file system operations, with support for multiple backends. Out of the box, AsyncToolkit comes with several HTTP backends (using libraries such as aiohttp, httpx, requests, and even pyodide for browser-based Python environments) and a file system tool. You can also easily register your own custom tools and extensions.

Features

  • Unified Async Interface: Standardized API for executing asynchronous operations.
  • Multiple HTTP Backends: Choose from aiohttp, httpx, requests (wrapped for async), or pyodide (in browser environments).
  • Extendable: Easily register and retrieve custom tools and extensions.
  • Built-in Tools: Includes sample tools for common tasks like HTTP requests and file system operations.
  • Test Suite: Comprehensive tests using pytest and tox to ensure reliability.

Installation

AsyncToolkit requires Python 3.10 or later. You can install the package and its optional dependencies using pip:

# Install the core package
pip install asynctoolkit

# For HTTP functionality, install one or more of the following:
pip install aiohttp        # For aiohttp backend
pip install httpx          # For httpx backend
pip install requests       # For requests backend
pip install pyodide        # For pyodide backend (if running in a Pyodide environment)

Quick Start

Here’s a brief example demonstrating how to use AsyncToolkit to perform an HTTP GET request and list directory contents:

import asyncio
from asynctoolkit.base import run_tool

async def main():
    # Example 1: File System Operation
    # Using the "filesystem" tool to list directory contents.
    file_list = await run_tool("filesystem", path=".", operation="list")
    print("Directory Contents:", file_list)

    # Example 2: HTTP Request
    # Using the "http" tool with the default (first registered) HTTP backend.
    TEST_URL = "https://httpbin.org/get"
    async with await run_tool("http", url=TEST_URL, method="GET") as response:
        status = await response.status()
        data = await response.json()
        print("HTTP Status:", status)
        print("Response JSON:", data)

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

Specifying HTTP Extensions

AsyncToolkit's HTTP tool supports multiple extensions. You can explicitly choose which backend to use by specifying the extension parameter:

# Example using the aiohttp backend explicitly
async with await run_tool("http", url="https://httpbin.org/get", method="GET", extension="aiohttp") as response:
    print("HTTP Status (aiohttp):", await response.status())

If no extension is specified, the tool will default to the first registered extension.

Extending AsyncToolkit

You can easily create and register your own asynchronous tools or extend existing ones.

Creating a Custom Tool

Define a new tool by subclassing AsyncTool and implement the asynchronous run() method:

from asynctoolkit.base import AsyncTool, register_tool

class MyCustomTool(AsyncTool):
    async def run(self, *args, **kwargs):
        # Your custom async operation here
        return "custom_result"

# Register the custom tool under a unique name
register_tool("my_custom", MyCustomTool)

# Running the custom tool later:
import asyncio
from asynctoolkit.base import run_tool

async def run_my_tool():
    result = await run_tool("my_custom")
    print(result)  # Outputs: custom_result

asyncio.run(run_my_tool())

Adding Extensions

For tools that support multiple implementations (like the HTTP tool), you can register extensions. Each extension is simply an asynchronous function that conforms to the tool’s expected interface. See the built-in HTTP tool in asynctoolkit.defaults.http for examples using aiohttp, httpx, requests, and pyodide.

License

This project is licensed under the terms of the MIT license.

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

asynctoolkit-0.3.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

asynctoolkit-0.3.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file asynctoolkit-0.3.0.tar.gz.

File metadata

  • Download URL: asynctoolkit-0.3.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asynctoolkit-0.3.0.tar.gz
Algorithm Hash digest
SHA256 93a00a941158dacc81d751b92a0fb7b5c8e1e540b6b76e47e742017425efc54a
MD5 cc3d34c07d264c2dc34e7c42af00a104
BLAKE2b-256 7fe24388bc06000f194501858ea85ae0a0502ff3d6bccf97972a547414ee8029

See more details on using hashes here.

Provenance

The following attestation bundles were made for asynctoolkit-0.3.0.tar.gz:

Publisher: version_publish_main.yml on JulianKimmig/asynctoolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asynctoolkit-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: asynctoolkit-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asynctoolkit-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51268542be970a429cc00f619880e2d1e263e6e310333326b940a5ae29537aa9
MD5 d7580af4996c2076e072b65da42d23a7
BLAKE2b-256 7767dd7d396706cc6e9e80963a4fc7f5a53a69e5bc3f134b5d58c3719c5dfb92

See more details on using hashes here.

Provenance

The following attestation bundles were made for asynctoolkit-0.3.0-py3-none-any.whl:

Publisher: version_publish_main.yml on JulianKimmig/asynctoolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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