Skip to main content

Ark for Python

The official Python SDK for Ark storage. It is framework-independent and provides:

  • Ark for Django, Flask, Celery, scripts, and synchronous workers.
  • AsyncArk for FastAPI, Starlette, aiohttp, and async workers.
  • Memory-bounded single and multipart uploads.
  • Typed result models and one normalized ArkError exception.
  • Optional access through Ark's S3-compatible endpoint using boto3.

Install

pip install nerdstack-ark

For S3-compatible access:

pip install "nerdstack-ark[s3]"

Python 3.10 or newer is required.

Synchronous usage

import os
from ark_py import Ark

with Ark(os.environ["ARK_API_TOKEN"]) as ark:
    folder = ark.folders.create("Product Media")
    file = ark.files.upload(
        "./hero.mp4",
        folder_id=folder.id,
        content_type="video/mp4",
    )
    download_url = ark.files.get_download_url(file.id, expires_in_seconds=600)
    print(download_url)

Filesystem paths stream directly from disk. A file-like object is also accepted; provide size and filename when it is not seekable:

file = ark.files.upload(
    request.stream,
    size=int(request.headers["content-length"]),
    filename="upload.bin",
)

The stream must produce exactly the declared number of bytes. Ark aborts an incomplete server-side session if the transfer fails, underflows, or overflows.

Asynchronous usage

import os
from ark_py import AsyncArk

async with AsyncArk(os.environ["ARK_API_TOKEN"]) as ark:
    file = await ark.files.upload("./hero.mp4", content_type="video/mp4")
    usage = await ark.usage()
    print(file.id, usage.storage.used_bytes)

AsyncArk.files.upload accepts paths, ordinary binary files, and AsyncIterable[bytes]. Async iterables require an exact size and filename.

Files, folders, images, and sessions

page = ark.files.list(folder_id=folder.id, limit=50)
file = ark.files.get(page.data[0].id)
ark.files.move(file.id, folder_id=None)
ark.files.delete(file.id)

folders = ark.folders.list(parent_id=None)
ark.folders.rename(folder.id, "Campaign Media")

image_url = ark.images.url(file.id)
signed_url = ark.images.signed_url(file.id, expires_in_seconds=600)

session = ark.create_client_session(ttl_seconds=900)
# Hand session.token to @nerdstackgrp/ark-client in the browser.

S3-compatible access

import os
from ark_py import create_s3_client

s3 = create_s3_client(
    access_key_id=os.environ["ARK_ACCESS_KEY_ID"],
    secret_access_key=os.environ["ARK_SECRET_ACCESS_KEY"],
)

s3.put_object(Bucket="product-media", Key="hero.jpg", Body=image_bytes)
objects = s3.list_objects_v2(Bucket="product-media", Prefix="photos/")

These must be Ark-issued S3 credentials. The helper configures SigV4 and path-style addressing for https://ark.nerdstackgrp.com/s3.

Errors

from ark_py import ArkError

try:
    ark.files.get("missing")
except ArkError as error:
    print(error.code, error.status, error.request_id, error.retryable)

Framework examples

Complete examples live in examples/:

  • Django upload view and application lifecycle.
  • Flask application factory and upload route.
  • FastAPI lifespan management and UploadFile streaming.

Keep ARK_API_TOKEN in server-side environment configuration. Never expose it to templates, frontend bundles, mobile apps, logs, or error responses.

Development

python -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/pytest
.venv/bin/ruff check .
.venv/bin/mypy
.venv/bin/python -m build
.venv/bin/twine check dist/*

License

MIT © Nerdstack.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nerdstack_ark-1.0.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

nerdstack_ark-1.0.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file nerdstack_ark-1.0.0.tar.gz.

File metadata

  • Download URL: nerdstack_ark-1.0.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for nerdstack_ark-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c0de44ca4265680866b38409f4084cf0c6e83b088fcb9c761e173a576ff64f24
MD5 d719e996b13b5c88ba12c8682214b98b
BLAKE2b-256 6b9618f3016f6633f25b95f9dc4b545feb4eaa90d54037bdf8db64a0bcb97064

See more details on using hashes here.

File details

Details for the file nerdstack_ark-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nerdstack_ark-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for nerdstack_ark-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35c5501c1cad30526c560a8fd6c59aea1dc54608b703e8980c9273b48c25665c
MD5 113846baa3ecf7ae6f2e380747ed9f89
BLAKE2b-256 6c5cc9a33691a81d26279f5f47666214315fa88198b61d51487fbbaa0c63cd0e

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.1

2 files

This release

1.0.0 This release

2 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