Portabyte Python SDK
Upload, deliver, and manage files from a Python server with portabyte.
Requirements
- Python 3.9 or later
- A Portabyte project API key (
pbt_sk_live_...)
Keep the key on your server. This package is not for browser code.
Install
pip install portabyte
Quick start
Create a project API key, then place a PDF named summary.pdf beside your script:
export PORTABYTE_API_KEY="pbt_sk_live_your_key_here"
Save this as quickstart.py:
import os
from portabyte import Portabyte
with Portabyte(os.environ["PORTABYTE_API_KEY"]) as portabyte:
asset = portabyte.files.upload("summary.pdf", visibility="public")
print(asset["id"], asset["publicUrl"])
Run python quickstart.py. The SDK creates an upload session, sends the file to its signed upload URL, and confirms it. The API endpoint is built in; you only provide the project key.
Async applications
Use AsyncPortabyte in an asyncio-based server. It offers the same files operations and closes its connection pool when the async with block ends:
import os
from portabyte import AsyncPortabyte
async def upload_summary():
async with AsyncPortabyte(os.environ["PORTABYTE_API_KEY"]) as portabyte:
return await portabyte.files.upload("summary.pdf", visibility="public")
For an interrupted multipart upload, call await portabyte.files.resume(session, path, state=saved_state, on_state_change=save_state). The callback may be a regular function or an async function; the SDK waits for it before uploading the next part.
Common tasks
with Portabyte(os.environ["PORTABYTE_API_KEY"]) as portabyte:
asset = portabyte.files.get(asset_id)
delivery = portabyte.files.url(asset_id)
page = portabyte.files.list(limit=20)
next_page = (
portabyte.files.list(cursor=page["cursor"], limit=20)
if page.get("cursor")
else None
)
portabyte.files.remove(asset_id)
Public files have stable delivery URLs. Private files receive short-lived signed URLs; request a fresh one when needed. Set path during upload to replace the current file at an application-owned path.
Large files use multipart upload automatically. To recover from an interrupted upload, persist the session returned by files.create() and the state passed to the callback:
from pathlib import Path
file = Path("video.mp4")
with Portabyte(os.environ["PORTABYTE_API_KEY"]) as portabyte:
session = portabyte.files.create(file.name, "video/mp4", file.stat().st_size)
# Save session somewhere durable before starting the transfer.
asset = portabyte.files.resume(
session,
file,
state=saved_state,
on_state_change=lambda state: save_upload_state(state),
)
If you need a direct browser upload, call files.prepare_browser_upload(...) on your server, send that result to the browser, then call files.confirm(asset_id) from your server after the upload succeeds. Never send the API key to the browser. See Browser uploads.
To abandon a multipart upload, call files.cancel(session, state=saved_state). The SDK attempts to abort the transfer and removes the pending asset even if its signed URL has expired.
Response shapes such as Asset, CreateSession, and ListAssetsResult are exported as type hints. Runtime responses remain plain dictionaries so newly added API fields remain accessible.
Errors
Failed requests raise PortabyteError:
from portabyte import PortabyteError
try:
asset = portabyte.files.get(asset_id)
except PortabyteError as error:
print(error.status, error.code, error.request_id)
raise
The error exposes status, code, and request_id when the API supplies them.
Client options
| Option | Purpose | Default |
|---|---|---|
api_key |
Server API key scoped to a project | Required |
max_retries |
Retries for reads and byte transfers | 2 |
timeout |
Request timeout in seconds | 300 |
Both Portabyte and AsyncPortabyte accept these options. The SDK retries reads and byte transfers on network failures, 429, and 5xx. It does not retry state-changing API requests.
When to use this SDK
Use it on a trusted server to upload and manage files, prepare direct browser uploads, and request delivery URLs. A browser can send file bytes to a signed upload URL prepared by your server; it must never receive your project API key.
Documentation
Development
uv run --with pytest pytest
uv run --with mypy mypy src/portabyte --ignore-missing-imports
uv run --with ruff==0.16.10 ruff format src tests README.md
uv run --with ruff==0.16.10 ruff format --check src tests README.md
uv build
Tests use a mock HTTP transport and do not require an API key.
Report SDK bugs in GitHub issues.
License
Metadata
Release files for portabyte 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| portabyte-0.1.0.tar.gz | 13.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| portabyte-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.0 kB
Release files / portabyte-0.1.0.tar.gz
| Download URL | portabyte-0.1.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b47403fdae41a15bd017a803712c2f1919c9ebf6f709b14c8e54517dc789678a
|
|
BLAKE2b-256 checksum How to use checksums |
ae7999353accd4c4d037e2e7636b109a54285ac184cec23a47b62cc3874975a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.
Transparency logRelease files / portabyte-0.1.0-py3-none-any.whl
| Download URL | portabyte-0.1.0-py3-none-any.whl |
|---|---|
| Size | 15.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fa4465476236af6c20e637c59737c4196b398efa34b0a88101406034cce6f0e
|
|
BLAKE2b-256 checksum How to use checksums |
34765e945be0d008c71b4017c1f83db327372b1da82fd96e3294ae42b7320853
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.
Transparency log