Skip to main content

No project description provided

Project description

vidcache-client

Python client for the vidcache REST API — a content-addressed video cache service with BLAKE3 exact deduplication and perceptual hash matching.

Installation

Install directly from the local package:

pip install ./client

Or add it to a requirements.txt:

dwilson-vidcache-client>=1.0.0

Requires: Python 3.11+, httpx>=0.27.0


Quick start

from vidcache_client import VidCacheClient

client = VidCacheClient("http://localhost:8020")

# Ingest a video URL — runs full dedup pipeline on the server
result = client.ingest(
    url="https://example.com/videos/abc123.mp4",
    bucket="videos",
    prefix="archive",
    meta={"title": "Cool video"},
)

print(result["hash"])    # BLAKE3 hex digest
print(result["status"])  # "new" | "duplicate" | "url_alias"

# Resolve a URL to its hash (no re-ingest)
entry = client.resolve("https://example.com/videos/abc123.mp4")

# Get metadata + all known source URLs
meta = client.get_meta(entry["hash"])
print(meta["duration_s"])
print(meta["aliases"])   # list of all ingested URLs for this video

# Download raw bytes (small files)
video_bytes = client.get_bytes(entry["hash"])

# Stream to a file (recommended for large files)
client.download_to_file(entry["hash"], "video.mp4")

# Stream with manual chunk iteration
with client.stream_video(entry["hash"]) as chunks:
    for chunk in chunks:
        process(chunk)

# Byte-range read (e.g. for seeking)
clip_bytes = client.get_bytes(entry["hash"], byte_range=(0, 1_000_000))

# Delete
client.delete(entry["hash"])

client.close()  # or use as a context manager

Use as a context manager to close the HTTP connection automatically:

with VidCacheClient("http://localhost:8020") as client:
    result = client.ingest(url=url, bucket="videos")

API reference

VidCacheClient(base_url, timeout=300.0, chunk_size=1_048_576)

Parameter Type Description
base_url str Base URL of the vidcache service, e.g. http://localhost:8020
timeout float Request timeout in seconds (default 300.0 — video ingest can be slow)
chunk_size int Byte chunk size for streamed video responses (default 1 MB)

ingest(url, bucket, prefix="", meta=None) → dict

Submit a video URL for caching. Runs the full dedup pipeline on the server (URL lookup → BLAKE3 exact hash → perceptual hash).

Parameter Type Description
url str Source URL of the video
bucket str Storage bucket name
prefix str (optional) Path prefix inside the bucket
meta dict (optional) Arbitrary metadata to store with the video

Returns dict with hash, status ("new" / "duplicate" / "url_alias"), file_path, and optionally phash_distance.


resolve(url) → dict | None

Look up whether a URL has been ingested before. Returns {"hash": …, "url": …} or None.


get_meta(content_hash) → dict | None

Retrieve full metadata for a stored video. Includes hash, size_bytes, duration_s, first_seen, aliases (all known source URLs), and any client-supplied meta. Returns None if not found.


get_bytes(content_hash, byte_range=None) → bytes

Download a stored video as raw bytes. Accepts an optional (start, end) inclusive byte range.


stream_video(content_hash, byte_range=None) → context manager

Stream a stored video as an iterable of byte chunks. Use as a context manager:

with client.stream_video(hash) as chunks:
    for chunk in chunks:
        ...

download_to_file(content_hash, dest, byte_range=None) → int

Stream a video directly to a local file. Returns the number of bytes written.


delete(content_hash) → None

Delete a cached video and all its URL aliases.


close() → None

Close the underlying HTTP connection pool. Called automatically when used as a context manager.

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

dwilson_vidcache_client-1.3.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

dwilson_vidcache_client-1.3.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file dwilson_vidcache_client-1.3.0.tar.gz.

File metadata

  • Download URL: dwilson_vidcache_client-1.3.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for dwilson_vidcache_client-1.3.0.tar.gz
Algorithm Hash digest
SHA256 b6181daa76e95ff1956442b928e295797fde42417456a5fb8b38efaf2028541a
MD5 2ae7bc06896e99538c09bcbaa6fa7886
BLAKE2b-256 7b074567f5b3573a8eb7b7e32ea406648b1d5a18cbf488a738d77d892d9db4ff

See more details on using hashes here.

File details

Details for the file dwilson_vidcache_client-1.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dwilson_vidcache_client-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a7e16a06dce449f6054886ef411945d17d8142effe9cf42c3dcc858a1326e9e
MD5 cdb35430d64203467b36071706dfb5a0
BLAKE2b-256 d6a7b5483df084650046739496dbe22c1b5b2dddd241c2bf37d90bd07d0e3e0d

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