Skip to main content

Python SDK for Numbers Protocol Capture API

Project description

Capture SDK (Python)

Python SDK for the Numbers Protocol Capture API. Register and manage digital assets with blockchain-backed provenance.

Installation

pip install numbersprotocol-capture-sdk

Quick Start

from numbersprotocol_capture import Capture

# Initialize client
capture = Capture(token="your-api-token")

# Register an asset
asset = capture.register("./photo.jpg", caption="My photo")
print(f"Registered: {asset.nid}")

# Retrieve asset
asset = capture.get(asset.nid)
print(f"Filename: {asset.filename}")

# Update metadata
updated = capture.update(
    asset.nid,
    caption="Updated caption",
    commit_message="Fixed typo"
)

# Get commit history
history = capture.get_history(asset.nid)
for commit in history:
    print(f"Action: {commit.action}, Author: {commit.author}")

# Get merged provenance data
tree = capture.get_asset_tree(asset.nid)
print(f"Creator: {tree.creator_name}")

File Input Types

The SDK accepts multiple file input formats:

# File path (string)
asset = capture.register("./photo.jpg")

# pathlib.Path
from pathlib import Path
asset = capture.register(Path("./photo.jpg"))

# Binary data (requires filename)
with open("photo.jpg", "rb") as f:
    data = f.read()
asset = capture.register(data, filename="photo.jpg")

Optional Signing

For cryptographic signing of assets using EIP-191:

asset = capture.register(
    "./photo.jpg",
    sign={"private_key": "0x...your-private-key"}
)

Context Manager

Use as a context manager for automatic resource cleanup:

with Capture(token="your-token") as capture:
    asset = capture.register("./photo.jpg")

API Reference

Capture(token, testnet=False, base_url=None)

Initialize the client.

Parameter Type Description
token str API authentication token
testnet bool Use testnet (default: False)
base_url str Custom API URL

capture.register(file, **options)

Register a new asset.

Parameter Type Description
file FileInput File path, Path, or bytes
filename str Required for binary input
caption str Asset description
headline str Title (max 25 chars)
public_access bool IPFS pinning (default: True)
sign dict {"private_key": "0x..."}

capture.update(nid, **options)

Update asset metadata.

Parameter Type Description
nid str Numbers ID
caption str Updated description
headline str Updated title
commit_message str Change description
custom_metadata dict Custom fields

capture.get(nid)

Retrieve a single asset by NID.

capture.get_history(nid)

Get commit history of an asset.

capture.get_asset_tree(nid)

Get merged provenance data.

Error Handling

from numbersprotocol_capture import (
    CaptureError,
    AuthenticationError,
    NotFoundError,
    ValidationError,
)

try:
    asset = capture.get("invalid-nid")
except NotFoundError as e:
    print(f"Asset not found: {e}")
except AuthenticationError as e:
    print(f"Auth failed: {e}")
except CaptureError as e:
    print(f"Error: {e.code} - {e.message}")

Requirements

  • Python 3.10+

License

MIT

Project details


Download files

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

Source Distribution

numbersprotocol_capture_sdk-0.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

numbersprotocol_capture_sdk-0.2.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file numbersprotocol_capture_sdk-0.2.0.tar.gz.

File metadata

File hashes

Hashes for numbersprotocol_capture_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 db4c3a6839e1106dbccb6164d98dc823720702013c4f12dbb47b1b7fde67bf92
MD5 efa1ce7beafbb3ae317a24507a8754e8
BLAKE2b-256 350f8fcbd9985f41a77563d227c293343ed5c913b61a95cfc1ea9a76896a3217

See more details on using hashes here.

File details

Details for the file numbersprotocol_capture_sdk-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for numbersprotocol_capture_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1649d00cf5dac195de88226e880cf6a771b12e94e673b8d6812b5f8127203fb
MD5 1fed38ef26fc6bc0c59a051272c480e1
BLAKE2b-256 13d069afa3be86543421df64f10d337edd6424cec32705998971042dbb793562

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page