Skip to main content

Python SDK for PFS (Plugin-based File System) Server

Project description

pypfs - PFS Python SDK

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

Installation

pip install pypfs

For local development:

pip install -e .

Quick Start

from pypfs import PFSClient

# Initialize client
client = PFSClient("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, PFS!")

# 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 pypfs import PFSClient, PFSClientError

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

API Reference

PFSClient

Constructor

  • PFSClient(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 pypfs/
ruff check pypfs/

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

pypfs-0.1.0.tar.gz (60.5 kB view details)

Uploaded Source

Built Distribution

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

pypfs-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pypfs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 02f2e337394d2010838962b856b8c4ab2c588d09b61c21fc9b5f0bd7744deeb2
MD5 43c73c079f83e3fab188267102bf1b4a
BLAKE2b-256 6b172eb4a9ee86cf573e30c967bacf142fc4615152aa849daa8768e509e7a1fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pypfs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for pypfs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e121c75d9fed2ac8244847d202f8411dddaa760c6ddfb015efa2a2c84dbf8d41
MD5 d41975b546f7e8b6a300ad9c3b356ceb
BLAKE2b-256 699a55c975e4672a7df582918fbf37f5f542dc0239f2186eccf99fe34ab9f987

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