Skip to main content

Unified async I/O for Hanzo AI - high-performance with uvloop fallback

Project description

hanzo-async

Unified async I/O for Hanzo AI - high-performance with uvloop fallback.

Features

  • Automatic uvloop configuration - Falls back to asyncio on Windows
  • Async file I/O - Read, write, append with aiofiles
  • Async path operations - exists, is_file, mkdir, etc.
  • Async subprocess execution - run_command, run_shell
  • Consistent patterns - Same API across all Hanzo packages

Installation

pip install hanzo-async

# With uvloop support (recommended for macOS/Linux)
pip install hanzo-async[uvloop]

Quick Start

from hanzo_async import (
    # Loop configuration
    configure_loop,
    using_uvloop,

    # File operations
    read_file,
    write_file,
    read_json,
    write_json,

    # Path operations
    path_exists,
    is_file,
    is_dir,
    mkdir,

    # Process operations
    run_command,
    run_shell,
)

# Check if using uvloop
if using_uvloop():
    print("Using uvloop for high-performance async")

# Async file operations
async def example():
    # Read/write files
    content = await read_file("/path/to/file.txt")
    await write_file("/path/to/output.txt", content)

    # JSON handling
    data = await read_json("/path/to/config.json")
    data["updated"] = True
    await write_json("/path/to/config.json", data)

    # Path operations
    if await path_exists("/path/to/file"):
        if await is_file("/path/to/file"):
            await unlink("/path/to/file")

    await mkdir("/path/to/new/dir", parents=True, exist_ok=True)

    # Run commands
    stdout, stderr, code = await run_command("ls", "-la")
    stdout, stderr, code = await run_shell("echo $HOME && pwd")

API Reference

Loop Configuration

  • configure_loop() - Configure uvloop (auto-called on import)
  • using_uvloop() - Check if uvloop is active
  • get_loop() - Get current event loop

File Operations

  • read_file(path) - Read file content
  • write_file(path, content) - Write content to file
  • append_file(path, content) - Append to file
  • read_json(path) - Read and parse JSON
  • write_json(path, data) - Write JSON to file
  • read_lines(path) - Read file as lines
  • write_lines(path, lines) - Write lines to file
  • read_bytes(path) - Read file as bytes
  • write_bytes(path, content) - Write bytes to file

Path Operations

  • path_exists(path) - Check if path exists
  • is_file(path) - Check if path is file
  • is_dir(path) - Check if path is directory
  • mkdir(path, parents=False, exist_ok=False) - Create directory
  • rmdir(path) - Remove empty directory
  • unlink(path, missing_ok=False) - Remove file
  • stat(path) - Get file/directory stats
  • listdir(path) - List directory contents
  • glob(pattern, root_dir=None, recursive=False) - Find files
  • rename(src, dst) - Rename/move file
  • copy(src, dst) - Copy file
  • copytree(src, dst) - Copy directory tree
  • rmtree(path) - Remove directory tree

Process Operations

  • run_command(*args) - Run command with args
  • run_shell(command) - Run shell command
  • check_command(command) - Check if command exists
  • which(command) - Find command path
  • start_background(*args) - Start background process

Why hanzo-async?

  1. Consistent async patterns - All Hanzo packages use the same I/O patterns
  2. High performance - uvloop provides 2-4x faster async on Unix
  3. Automatic fallback - Works on Windows with standard asyncio
  4. No event loop blocking - All operations are truly async
  5. Easy to use - Simple function-based API

License

MIT

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

hanzo_async-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

hanzo_async-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hanzo_async-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for hanzo_async-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b1223049a90b846cce8f3f763a61061f7a353acb981242d83f8476d516d793ba
MD5 1b5915222a7040a76a03bfd0ad7dfea4
BLAKE2b-256 c05098dce04e47d666b701fc8ed85037d4144cd802018be987579d512a2b5148

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for hanzo_async-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecba8b338d2be6d84b339140d6f1802f5cb9ed75acadd997c0f6fd15dac2042c
MD5 d1118d37704a5def4700fc451b98b415
BLAKE2b-256 27aeb94352e57fadead2e6fd48acd60d5e0a1ab9a68b2acaa0a80c3277a31c63

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