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(health)

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

# Read file content
content = client.cat("/path/to/file.txt")
print(content.decode())

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

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

# Remove file or directory
client.rm("/path/to/file.txt")
client.rm("/path/to/directory", recursive=True)

Advanced Usage

Streaming Operations

# 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

# List mounted plugins
mounts = client.mounts()

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

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

Plugin Management

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

# List loaded plugins
plugins = client.list_plugins()
print(plugins)

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

Search with Grep

# Simple search
result = client.grep("/local/logs", "error")
print(f"Found {result['count']} matches")
for match in result['matches']:
    print(f"{match['file']}:{match['line']}: {match['content']}")

# Recursive case-insensitive search
result = client.grep("/local", "warning|error", recursive=True, case_insensitive=True)

File Operations

# Get file info
info = client.stat("/path/to/file.txt")
print(f"Size: {info['size']}, Mode: {info['mode']}")

# Move/rename file
client.mv("/old/path.txt", "/new/path.txt")

# Change permissions
client.chmod("/path/to/file.txt", 0o644)

# Copy file (read + write)
content = client.cat("/source.txt")
client.write("/destination.txt", content)

Error Handling

from pyagfs import AGFSClient, AGFSClientError

try:
    client = AGFSClient("http://localhost:8080")
    content = client.cat("/nonexistent/file.txt")
except AGFSClientError as e:
    print(f"Error: {e}")

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
  • write(path, data) - Write data to file
  • 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

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
  • load_plugin(library_path) - Load an external plugin
  • unload_plugin(library_path) - Unload an external plugin

Health Check

  • health() - Check server health

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-0.1.4.tar.gz (64.9 kB view details)

Uploaded Source

Built Distribution

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

pyagfs-0.1.4-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyagfs-0.1.4.tar.gz
Algorithm Hash digest
SHA256 50a03b3ec0875cbe7d7fbc3346648fe535e4e11f75b3ae0b60a73e8c87f334f8
MD5 1ece811e864f1ee104b44d023595731e
BLAKE2b-256 c999e95c3a07415d0f11e0c5345b6a577df3a54044513196d56d6f5647536f5e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyagfs-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 601f612af2889f413360f880f1e0735b6d99d5f33922a975f4c445792dcf5ae8
MD5 c07c21aeb6aad4b229e33ec5faf6c648
BLAKE2b-256 6e139d285b3c74ebb33e419d53e8ef8f6d108cf2788df631fed9c1abfd070eaa

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