Skip to main content

ppdrive-python-sdk

Python SDK for PPDRIVE — a self-hosted, open-source object storage service.

  • Sync client built on httpx
  • Full coverage of the PPDRIVE client API
  • Typed exceptions for every HTTP error
  • Resumable uploads and range downloads
  • Zero runtime dependencies beyond httpx

Installation

pip install ppdrive

Quick Start

from ppdrive import PPDriveClient

with PPDriveClient("http://localhost:8000", "YOUR_CLIENT_TOKEN") as client:
    # Create a bucket
    bucket = client.create_bucket(
        label="Documents",
        root_path="storage/docs",
        public=False,
    )
    
    # Upload a file
    with open("report.pdf", "rb") as f:
        client.upload_file(
            "report.pdf",
            f,
            bucket=bucket,
            content_type="application/pdf",
        )
        
    # Download it back
    data = client.download_file(bucket, "report.pdf", expires=300)
    with open("report_copy.pdf", "wb") as f:
        f.write(data)

Authentication

Every request sends your client token in the x-ppdrive-client header. If your server uses a custom header key (see client_header_key in the server config), pass it explicitly:

client = PPDriveClient(
    "http://localhost:8000",
    "YOUR_CLIENT_TOKEN",
    client_header_key="x-my-custom-header",
)

Resumable Uploads

For files ≥ 2 MB, pass resumable=True. Chunk size defaults to 1 MB:

with open("large.bin", "rb") as f:
    client.upload_file(
        "large.bin",
        f,
        bucket=bucket,
        resumable=True,
        chunk_size=2 * 1024 * 1024,
        on_progress=lambda sent, total: print(f"{sent}/{total}"),
    )

Range Downloads

# First 1024 bytes
head = client.download_file(bucket, "video.mp4", range=(0, 1023))

# Bytes 1024–2047
mid = client.download_file(bucket, "video.mp4", range=(1024, 2047))

# From 1024 to the end
tail = client.download_file(bucket, "video.mp4", range=(1024, None))

Signed URLs

Generate upload or download links without transferring data yourself:

upload_url = client.sign_upload_url(
    "incoming/report.pdf",
    bucket=bucket,
    content_type="application/pdf",
    target_filesize=1024,
)

download_url = client.sign_download_url(bucket, "report.pdf", expires=600)

Permissions

client.grant_permission(
    bucket,
    path="report.pdf",
    grantee="OTHER_CLIENT_PID",
    grantee_type="client",
    permission="read",
)

perms = client.list_permissions(bucket, path="report.pdf")

client.revoke_permission(
    bucket,
    path="report.pdf",
    grantee="OTHER_CLIENT_PID",
    grantee_type="client",
)

Error Handling

All API errors raise subclasses of PPDriveError:

from ppdrive import (
    PPDriveClient,
    AuthorizationError,
    NotFoundError,
    PayloadTooLargeError,
    PPDriveError,
)

try:
    client.download_file(bucket, "missing.pdf", expires=300)
except NotFoundError:
    print("No such file")
except AuthorizationError:
    print("Access denied")
except PayloadTooLargeError:
    print("File too large — use resumable upload")
except PPDriveError as e:
    print(f"HTTP {e.status}: {e.message}")
Status Exception
400 ValidationError
401 AuthenticationError
403 AuthorizationError
404 NotFoundError
409 ConflictError
413 PayloadTooLargeError
416 RangeError
429 RateLimitError
500 ServerError

API Reference

Method Description
upload_file(path, data, **opts) Upload a file (single or chunked)
upload_folder(path, **opts) Create a folder
sign_upload_url(path, **opts) Return a signed upload URL
download_file(bucket, path, **opts) Download a private file
download_public_file(url) Download from a public bucket
sign_download_url(bucket, path, expires=...) Return a signed download URL
create_bucket(label=..., **opts) Create a bucket, returns its PID
grant_permission(bucket, **opts) Grant a file-level permission
revoke_permission(bucket, **opts) Revoke a file-level permission
list_permissions(bucket, path=None) List permissions
login(**credentials) Authenticate against /auth/login

Development

python -m venv .venv
source .venv/bin/activate   # or .\.venv\Scripts\Activate.ps1 on Windows
pip install -e ".[dev]"
pytest -q

License

Licensed under the PolyForm Noncommercial License. Commercial use requires permission.

Metadata

Release files for ppdrive 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ppdrive 0.1.1
File Size Uploaded
ppdrive-0.1.1.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ppdrive 0.1.1
File Interpreter ABI Platform
ppdrive-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 19.3 kB

Release files / ppdrive-0.1.1.tar.gz

Download URL ppdrive-0.1.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
cadcfc61787213a531070f2a89d953fc4c0a2007ed7246bff492795dc126d49b
BLAKE2b-256 checksum
How to use checksums
1412debf70b2f535fe9ca2008272b9d69d1ae076e47fd9908ad05349718349c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release files / ppdrive-0.1.1-py3-none-any.whl

Download URL ppdrive-0.1.1-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1cbe2078018b7863f10a9573024f7b8d100c5ec036c9ce135e4274314a00885f
BLAKE2b-256 checksum
How to use checksums
401d0f3d74ec26babbf59353a1bce7e5bd500c4b0ca694b1da277c304ca4b96d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page