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.0

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.0
File Size Uploaded
ppdrive-0.1.0.tar.gz 6.3 kB Details

Built distribution (wheel)

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

Total release size: 13.3 kB

Release files / ppdrive-0.1.0.tar.gz

Download URL ppdrive-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
36eb93720dfc96ed2a694cf024dfd88bd6da51156c20897fa00b6b3026d7e98b
BLAKE2b-256 checksum
How to use checksums
f2a35175999037497bfe419581b1daf9da3de0a800288e5c59501a57134a7512
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.0-py3-none-any.whl

Download URL ppdrive-0.1.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8535f79d371ffb5c85058bff3a08bcbdc335838c1ff3153bfa35c9d0a3479fda
BLAKE2b-256 checksum
How to use checksums
fbe2601ea385eb7c8371843712653e7194ed7e8a83c5905121613990382c7dc9
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

0.1.1

2 release files

This release

0.1.0 This release

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