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.1.tar.gz (17.4 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.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nerdstack_ark-1.0.1.tar.gz
  • Upload date:
  • Size: 17.4 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.1.tar.gz
Algorithm Hash digest
SHA256 771f50e2b185e1ae5106d2e5fa18dfa7408614feca08f8d931e6dfd4f6bf3e7b
MD5 7d35eac998419c24147dfdb4729fd49c
BLAKE2b-256 b80c836851f22941a4fcc5253a47b5ce3e74adb85c0c5f6c4cc096d0911b6b3e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nerdstack_ark-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30cf1198f87470f05cba3f15e6d5aee34eae1fc94aac093ba41722353630c034
MD5 dcfc3b8b8ba58f917067140fdbed21ac
BLAKE2b-256 6c43f0ee3a6fee78ec5830650a911d31fd036c6a479847fb648cc6130b2029b9

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

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