Metadata-Version: 2.5
Name: ppdrive
Version: 0.1.1
Summary: Python SDK for PPDRIVE — self-hosted object storage
Project-URL: Homepage, https://github.com/dududaa/ppdrive
Project-URL: Repository, https://github.com/Agentfield247/ppdrive-python-sdk
Author: Muhammed Bamidele
License: Copyright (c) 2026 Muhammed Bamidele
        
        # PolyForm Noncommercial License 1.0.0
        
        <https://polyformproject.org/licenses/noncommercial/1.0.0>
        
        ## Acceptance
        
        In order to get any license under these terms, you must agree
        to them as both strict obligations and conditions to all
        your licenses.
        
        ## Copyright License
        
        The licensor grants you a copyright license for the
        software to do everything you might do with the software
        that would otherwise infringe the licensor's copyright
        in it for any permitted purpose.  However, you may
        only distribute the software according to [Distribution
        License](#distribution-license) and make changes or new works
        based on the software according to [Changes and New Works
        License](#changes-and-new-works-license).
        
        ## Distribution License
        
        The licensor grants you an additional copyright license
        to distribute copies of the software.  Your license
        to distribute covers distributing the software with
        changes and new works permitted by [Changes and New Works
        License](#changes-and-new-works-license).
        
        ## Notices
        
        You must ensure that anyone who gets a copy of any part of
        the software from you also gets a copy of these terms or the
        URL for them above, as well as copies of any plain-text lines
        beginning with `Required Notice:` that the licensor provided
        with the software.  For example:
        
        > Required Notice: Copyright Muhammed Bamidele (https://github.com/Agentfield247)
        
        ## Changes and New Works License
        
        The licensor grants you an additional copyright license to
        make changes and new works based on the software for any
        permitted purpose.
        
        ## Patent License
        
        The licensor grants you a patent license for the software that
        covers patent claims the licensor can license, or becomes able
        to license, that you would infringe by using the software.
        
        ## Noncommercial Purposes
        
        Any noncommercial purpose is a permitted purpose.
        
        ## Personal Uses
        
        Personal use for research, experiment, and testing for
        the benefit of public knowledge, personal study, private
        entertainment, hobby projects, amateur pursuits, or religious
        observance, without any anticipated commercial application,
        is use for a permitted purpose.
        
        ## Noncommercial Organizations
        
        Use by any charitable organization, educational institution,
        public research organization, public safety or health
        organization, environmental protection organization,
        or government institution is use for a permitted purpose
        regardless of the source of funding or obligations resulting
        from the funding.
        
        ## Fair Use
        
        You may have "fair use" rights for the software under the
        law. These terms do not limit them.
        
        ## No Other Rights
        
        These terms do not allow you to sublicense or transfer any of
        your licenses to anyone else, or prevent the licensor from
        granting licenses to anyone else.  These terms do not imply
        any other licenses.
        
        ## Patent Defense
        
        If you make any written claim that the software infringes or
        contributes to infringement of any patent, your patent license
        for the software granted under these terms ends immediately. If
        your company makes such a claim, your patent license ends
        immediately for work on behalf of your company.
        
        ## Violations
        
        The first time you are notified in writing that you have
        violated any of these terms, or done anything with the software
        not covered by your licenses, your licenses can nonetheless
        continue if you come into full compliance with these terms,
        and take practical steps to correct past violations, within
        32 days of receiving notice.  Otherwise, all your licenses
        end immediately.
        
        ## No Liability
        
        ***As far as the law allows, the software comes as is, without
        any warranty or condition, and the licensor will not be liable
        to you for any damages arising out of these terms or the use
        or nature of the software, under any kind of legal claim.***
        
        ## Definitions
        
        The **licensor** is the individual or entity offering these
        terms, and the **software** is the software the licensor makes
        available under these terms.
        
        **You** refers to the individual or entity agreeing to these
        terms.
        
        **Your company** is any legal entity, sole proprietorship,
        or other kind of organization that you work for, plus all
        organizations that have control over, are under the control of,
        or are under common control with that organization.  **Control**
        means ownership of substantially all the assets of an entity,
        or the power to direct its management and policies by vote,
        contract, or otherwise.  Control can be direct or indirect.
        
        **Your licenses** are all the licenses granted to you for the
        software under these terms.
        
        **Use** means anything you do with the software requiring one
        of your licenses.
License-File: LICENSE
Requires-Python: >=3.9
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: respx>=0.21; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Description-Content-Type: text/markdown

# ppdrive-python-sdk

Python SDK for [PPDRIVE](https://github.com/dududaa/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

```bash
pip install ppdrive
```

## Quick Start

```python
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:

```python
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:

```python
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

```python
# 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:

```python
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

```python
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`:

```python
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

```bash
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.
