Skip to main content

crabcrop_url

Build and sign crabcrop URLs from Python. Standard library only; the signing scheme is specified in spec/url-signing.md and this package runs the canonical spec/test-vectors.json as its test suite, so it cannot drift from the server.

Usage

from crabcrop_url import build_url, build_srcset, purge_group_signature, purge_signature, sign, upload_signature, verify

# A signed URL. The operation string is passed verbatim and may
# contain several segments and preset: references.
url = build_url(
    "https://images.example.com",
    "your-secret",
    "crop:1200x630:smart/filters:format(webp)",
    "https://example.com/photo.jpg",
)

# An expiring URL (unix seconds), emitted as a leading exp: segment.
expiring = build_url(
    "https://images.example.com",
    "your-secret",
    "300x200",
    "https://example.com/photo.jpg",
    expires=1893456000,
)

# A responsive srcset: one {width}x0 URL per width.
srcset = build_srcset(
    "https://images.example.com",
    "your-secret",
    "https://example.com/photo.jpg",
    [400, 800, 1200],
)

# The raw signature for a remainder, if you assemble URLs yourself.
signature = sign("your-secret", "300x200/https://example.com/photo.jpg")

# Verify a signature in constant time (malformed tags return False).
ok = verify("your-secret", signature, "300x200/https://example.com/photo.jpg")

# Purge signatures for the server's /purge and /purge-group endpoints
# are domain-separated under a derived subkey; the helpers sign the
# right strings so callers never assemble them by hand.
purge = purge_signature("your-secret", "300x200/https://example.com/photo.jpg")
group = purge_group_signature("your-secret", "thumb")

# Upload signatures for the server's PUT /upload/<signature>/<name>
# endpoint live in a third domain, under their own derived subkey.
# Pass an expiry (unix seconds) for a token that stops working
# then; its path is /upload/<signature>/exp:<expiry>/<name>.
upload = upload_signature("your-secret", "heroes/photo.jpg")
expiring = upload_signature("your-secret", "heroes/photo.jpg", 1893456000)

Pass None as the secret to produce the literal unsafe signature segment, for servers running with CRABCROP_ALLOW_UNSAFE or in presets-only mode. The secret may be str or bytes.

Tests

python3 -m unittest discover -s tests

Metadata

Release files for crabcrop-url 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crabcrop-url 0.3.1
File Size Uploaded Provenance
crabcrop_url-0.3.1.tar.gz 7.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for crabcrop-url 0.3.1
File Interpreter ABI Platform
crabcrop_url-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / crabcrop_url-0.3.1.tar.gz

Download URL crabcrop_url-0.3.1.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4b522d34f15087a50c319c0e9104c242c28e399be57c2ddeebf0c3139a2f4c00
BLAKE2b-256 checksum
How to use checksums
07be6bdec51c6ffe9d0d62f39b26e0def9bae68c0c8ed4df51c17081bab4aec4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / crabcrop_url-0.3.1-py3-none-any.whl

Download URL crabcrop_url-0.3.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06e1e9050f7987799230a5d59e48dd7079d44d1f9362b922b70ba83bf2013a3d
BLAKE2b-256 checksum
How to use checksums
fe334911ae24860318c0d4652cdfebf4f7d398db5518c6fc554cf4bb5c244f1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for crabcrop-url 0.3.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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