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.1.0.tar.gz (9.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.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for asynctoolkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e861f37f4099181d1ccc99e9dc697b48df81db95b7b8155ca77226ca6ecc4ff6
MD5 8c1202d0899cf1ff6aeb4cec20bf5f0c
BLAKE2b-256 adefc4a1ab185127619f13319fd70f3eea2e6d6ece428215e2c2d7bbf7f4a228

See more details on using hashes here.

Provenance

The following attestation bundles were made for asynctoolkit-0.1.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.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for asynctoolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0794ad6ed3b1221ba56b10bec821dbf051b8b1d72421e9b60bbd2e20a12d239
MD5 4dd910ca91d55db004b9b6a1838e8f02
BLAKE2b-256 cf35381d15894b14f77850e8408ebe4c15ebb7c21e03714a7bd88944b0db4dc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for asynctoolkit-0.1.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