Skip to main content

一个统一的路径处理库,支持本地文件系统、HTTP 和 S3 存储的路径操作

Project description

Omni-Pathlib

中文文档 PyPI version Python Version License Downloads GitHub Stars GitHub Issues

Dependencies

Omni-Pathlib is a unified path handling library that supports path operations for local file systems, HTTP, and S3 storage. It provides both synchronous and asynchronous APIs, making it easy and consistent to operate files across different storage systems.

Installation

pip install omni-pathlib

Basic Usage

from omni_pathlib import OmniPath

# Create different types of paths
http_path = OmniPath("https://example.com/file.txt")
s3_path = OmniPath("s3://my-bucket/path/to/file.txt")
local_path = OmniPath("/local/path/to/file.txt")

# Read file content
content = http_path.read_text()  # Read from HTTP
s3_content = s3_path.read_text()  # Read from S3
local_content = local_path.read_text()  # Read from local

# Asynchronous operations
async def main():
    content = await http_path.async_read_text()
    s3_content = await s3_path.async_read_text()
    local_content = await local_path.async_read_text()

Features

  • Unified path operation interface
  • Supports local file systems, HTTP, and S3 storage
  • Synchronous and asynchronous APIs
  • HTTP supports caching and resuming downloads
  • S3 supports complete bucket operations
  • Local file system supports standard path operations

Function Interface Description

Basic Operations

All storage types support the following operations:

# Path attributes
path.name      # Get the path name
path.stem      # Get the path name without suffix
path.suffix    # Get the path suffix
path.parent    # Get the parent path
path.protocol  # Get the protocol type ('file', 'http', 's3')

# Basic operations
path.exists()             # Check if the path exists
path.iterdir()            # Iterate through directory contents
path.stat()               # Get file information (size, modification time, etc.)
path.read_bytes()         # Read binary content
path.read_text()          # Read text content
path.write_bytes(data)    # Write binary content
path.write_text(data)     # Write text content
path.delete()             # Delete file

# All operations have corresponding asynchronous versions
await path.async_exists()
await path.async_iterdir()
# ... and so on

Local File System Specific Operations

  • mkdir(parents=False, exist_ok=False) / async_mkdir() - Create a directory
  • rmdir() / async_rmdir() - Remove an empty directory
  • rename(target) / async_rename(target) - Rename a file/directory
  • is_dir() / async_is_dir() - Check if it is a directory
  • is_file() / async_is_file() - Check if it is a file

HTTP Specific Features

  • Supports resuming downloads
  • Automatically caches downloaded content
  • Does not support write and delete operations

S3 Specific Features

  • Fully supports S3 bucket operations
  • Supports custom endpoints
  • Supports multiple authentication methods
  • Supports specifying profile in URL scheme

S3 Profile Configuration Priority

Configuration priority from high to low:

  1. Configuration passed directly as parameters
  2. Profile specified in URL scheme (e.g., s3+my_profile://bucket/key)
  3. Configuration through environment variable AWS_PROFILE
  4. default profile in configuration file
  5. The first profile found in the configuration file

S3 URL Scheme Example

# Parameter priority is higher than URL scheme
path = OmniPath(
    "s3+my_profile://bucket/key",
    profile_name="other_profile"  # Will use other_profile instead of my_profile
)

# Specify profile through URL scheme
path = OmniPath("s3+my_profile://bucket/key")  # Will use my_profile configuration

# Specify profile through environment variable
os.environ["AWS_PROFILE"] = "other_profile"
path = OmniPath("s3://bucket/key")  # Will use other_profile configuration

# Specify profile through configuration file
path = OmniPath("s3://bucket/key")  # Will use default configuration (if exists) or the first found configuration

S3 Profiles Retrieval Logic

  • Retrieve environment variable configurations from AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, OSS_ENDPOINT, S3_ENDPOINT, AWS_ENDPOINT_URL. These configurations will default to the default profile but can be specified to other named profiles by adding a prefix, e.g., my_profile__AWS_ACCESS_KEY_ID=my_access_key_id will go into the profile named my_profile.
  • Load configurations from the configuration file path obtained from the environment variable AWS_SHARED_CREDENTIALS_FILE, defaulting to ~/.aws/credentials.

Development

Install Dependencies

uv sync

Run Tests

uv run pytest

Commit

pre-commit install
cz commit

Release

cz bump

git push --follow-tags

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

omni_pathlib-0.3.2.tar.gz (132.3 kB view details)

Uploaded Source

Built Distribution

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

omni_pathlib-0.3.2-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file omni_pathlib-0.3.2.tar.gz.

File metadata

  • Download URL: omni_pathlib-0.3.2.tar.gz
  • Upload date:
  • Size: 132.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for omni_pathlib-0.3.2.tar.gz
Algorithm Hash digest
SHA256 5b098136742b01412240856ecc932ca1294cec45a8ea092f248436a10061c974
MD5 e9443544fbee371b8a39b8d6f3ae6616
BLAKE2b-256 298417c967de705dcfa3ae4448974da9964861951d1015cb92da15ecb954e707

See more details on using hashes here.

Provenance

The following attestation bundles were made for omni_pathlib-0.3.2.tar.gz:

Publisher: publish-to-pypi.yml on Haskely/omni-pathlib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file omni_pathlib-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: omni_pathlib-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for omni_pathlib-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c7d0b73d5558b367e6b2d1c8b216c700d2b05bc9de391651a446e13f17ef7897
MD5 9fd325d7c4c8b96d815285abbb777854
BLAKE2b-256 24db9529549c6a54fac5db1ce9e69ded7205e866fde822cbe107a80423e3c9f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for omni_pathlib-0.3.2-py3-none-any.whl:

Publisher: publish-to-pypi.yml on Haskely/omni-pathlib

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