Skip to main content

Python SDK for AGFS (Pluggable File System) Server

Project description

pyagfs - AGFS Python SDK

Python SDK for interacting with AGFS (Plugin-based File System) Server API.

See more details at c4pt0r/agfs

Installation

pip install pyagfs

For local development:

pip install -e .

Quick Start

from pyagfs import AGFSClient

# Initialize client
client = AGFSClient("http://localhost:8080")

# Check server health
health = client.health()
print(f"Server version: {health.get('version', 'unknown')}")

# List directory contents
files = client.ls("/")
for file in files:
    print(f"{file['name']} - {'dir' if file['isDir'] else 'file'}")

# Create a new directory
client.mkdir("/test_dir")

# Write to a file
client.write("/test_dir/hello.txt", b"Hello, AGFS!")

# Read file content
content = client.cat("/test_dir/hello.txt")
print(content.decode())

# Get file info
info = client.stat("/test_dir/hello.txt")
print(f"Size: {info['size']} bytes")

# Remove file and directory
client.rm("/test_dir", recursive=True)

High-Level File Operations

The SDK provides helper functions for common operations like copying files within AGFS or transferring files between the local filesystem and AGFS.

from pyagfs import AGFSClient, cp, upload, download

client = AGFSClient("http://localhost:8080")

# Upload local file or directory to AGFS
upload(client, "./local_data", "/remote_data", recursive=True)

# Download file or directory from AGFS to local
download(client, "/remote_data/config.json", "./local_config.json")

# Copy files within AGFS
cp(client, "/remote_data/original.txt", "/remote_data/backup.txt")

Advanced Usage

Streaming Operations

Useful for handling large files or long-running search results.

# Stream file content
response = client.cat("/large/file.log", stream=True)
for chunk in response.iter_content(chunk_size=8192):
    process(chunk)

# Stream grep results
for match in client.grep("/logs", "error", recursive=True, stream=True):
    if match.get('type') == 'summary':
        print(f"Total matches: {match['count']}")
    else:
        print(f"{match['file']}:{match['line']}: {match['content']}")

Mount Management

Dynamically mount different filesystem backends.

# List mounted plugins
mounts = client.mounts()

# Mount a memory filesystem
client.mount("memfs", "/test/mem", {})

# Mount a SQL filesystem
client.mount("sqlfs", "/test/db", {
    "backend": "sqlite",
    "db_path": "/tmp/test.db"
})

# Unmount a path
client.unmount("/test/mem")

Plugin Management

Load and unload external plugins (shared libraries).

# Load external plugin
result = client.load_plugin("./plugins/myplugin.so")

# List loaded plugins
plugins = client.list_plugins()

# Get detailed plugin info
plugin_infos = client.get_plugins_info()

# Unload plugin
client.unload_plugin("./plugins/myplugin.so")

Search and Integrity

# Recursive case-insensitive search
result = client.grep("/local", "warning|error", recursive=True, case_insensitive=True)
print(f"Found {result['count']} matches")

# Calculate file digest (hash)
# Supported algorithms: "xxh3" (default), "md5"
result = client.digest("/path/to/file.txt", algorithm="xxh3")
print(f"Hash: {result['digest']}")

API Reference

AGFSClient

Constructor

  • AGFSClient(api_base_url, timeout=10) - Initialize client with API base URL

File Operations

  • ls(path="/") - List directory contents
  • cat(path, offset=0, size=-1, stream=False) - Read file content (alias: read)
  • write(path, data, max_retries=3) - Write data to file with retry logic
  • create(path) - Create new empty file
  • rm(path, recursive=False) - Remove file or directory
  • stat(path) - Get file/directory information
  • mv(old_path, new_path) - Move/rename file or directory
  • chmod(path, mode) - Change file permissions
  • touch(path) - Update file timestamp
  • digest(path, algorithm="xxh3") - Calculate file hash

Directory Operations

  • mkdir(path, mode="755") - Create directory

Search Operations

  • grep(path, pattern, recursive=False, case_insensitive=False, stream=False) - Search for pattern in files

Mount Operations

  • mounts() - List all mounted plugins
  • mount(fstype, path, config) - Mount a plugin dynamically
  • unmount(path) - Unmount a plugin

Plugin Operations

  • list_plugins() - List all loaded external plugins
  • get_plugins_info() - Get detailed info about loaded plugins
  • load_plugin(library_path) - Load an external plugin
  • unload_plugin(library_path) - Unload an external plugin

Health Check

  • health() - Check server health

Helper Functions

  • cp(client, src, dst, recursive=False, stream=False) - Copy files/directories within AGFS
  • upload(client, local_path, remote_path, recursive=False, stream=False) - Upload from local to AGFS
  • download(client, remote_path, local_path, recursive=False, stream=False) - Download from AGFS to local

Development

Running Tests

pip install -e ".[dev]"
pytest

Code Formatting

black pyagfs/
ruff check pyagfs/

License

See LICENSE file for details.

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

pyagfs-1.4.0.tar.gz (67.7 kB view details)

Uploaded Source

Built Distribution

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

pyagfs-1.4.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pyagfs-1.4.0.tar.gz.

File metadata

  • Download URL: pyagfs-1.4.0.tar.gz
  • Upload date:
  • Size: 67.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pyagfs-1.4.0.tar.gz
Algorithm Hash digest
SHA256 e4c942298f069bee0e910bd011d09b37b1a60e051ef4595c403f86e06f58440a
MD5 2dfb178edc3bf2e3374c13c48e99f173
BLAKE2b-256 24a4b13bd3eca0f37129bfa97c7b103e92792e95b3bd3739a5529e7a0606068d

See more details on using hashes here.

File details

Details for the file pyagfs-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: pyagfs-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pyagfs-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1e33186ce094031e247be773a7203889e927b8e067b348d1a6f9556979ca03
MD5 fd9320fa842f1a32e8d765532da7d6f7
BLAKE2b-256 08eb1cab816f496d24909bebf7bee4de93d4d82b9e92d0ecd9cdcb72215d713e

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