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.2.tar.gz (10.3 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.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asynctoolkit-0.1.2.tar.gz
  • Upload date:
  • Size: 10.3 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.2.tar.gz
Algorithm Hash digest
SHA256 68bfb85c5de23218d1b070830ceda5d147966501391210699086c22241daf2bb
MD5 e294b8363a2f0e033be956e817d3d23c
BLAKE2b-256 b7d2c3b12658e306e6cfb60099bb5b4d979819318dc80649c42a84ee9d27abb3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: asynctoolkit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 50fe3f93b5046b46da66c4cd29fc0993e5c640b4b12dfa76c1f10cd28138ccfb
MD5 2d3bf7374fd935dd2d6ea96539d31bac
BLAKE2b-256 8c41fa18de2a0797b17b038fb3216b1565fa4405f97acc820019a9ed5681b908

See more details on using hashes here.

Provenance

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