Skip to main content

Sign and verify URLs using HMAC for secure temporary access.

Project description

signed-urls

Latest Commit Tests Status Code Coverage
Package version Python Version

Introduction

A signed URL is a URL that grants temporary, limited access to a resource, such as a file in cloud storage. It includes an expiration date and a digital signature in its query string, which authenticates the request and ensures the URL hasn't been altered. This allows users without direct credentials to perform a specific action, like downloading a file, for a limited time.

How signed URLs work?

  1. A server creates a standard URL and adds parameters like an expiration time.
  2. The server generates a digital signature using a secret key and appends it to the URL.
  3. The signed URL is shared with the user.
  4. When the user accesses the URL, the resource server verifies the signature and checks the expiration time.
  5. If the signature is valid and the URL hasn't expired, access to the resource is granted.

Use cases

  • Secure file downloads and uploads allowing temporary access.
  • Granting temporary access to private resources without sharing credentials.
  • Time-limited access to APIs for third-party applications.

signed-urls package

The signed-urls package provides a simple way to generate and verify signed URLs.

Installation

pip install signed-urls

Basic usage

from signed_urls import sign_url, verify_signed_url

method = "GET"
secret_key = "Top-Secret-Key"
url = "https://example.com/resource/1?owner=alice"
hashing_algorithm = "SHA256"
sign_format = "base64"

# Generate a signed URL
signed_url = sign_url(
    method=method,
    url=url,
    secret_key=secret_key,
    ttl=300,
    algorithm=hashing_algorithm,
    sign_format=sign_format
)
    
# Verify the signed URL
is_valid = verify_signed_url(
    method=method,
    signed_url=signed_url,
    secret_key=secret_key,
    algorithm=hashing_algorithm,
    sign_format=sign_format
)

print(f"Is the signed URL valid? {is_valid}")

Supported hashing algorithms

  • SHA256
  • SHA512
  • BLAKE2B
  • BLAKE2S

Supported sign formats

  • base64: creates signature as base64 ASCII string
  • hex: creates signature as hexadecimal string

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

signed_urls-0.1.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

signed_urls-0.1.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file signed_urls-0.1.0.tar.gz.

File metadata

  • Download URL: signed_urls-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for signed_urls-0.1.0.tar.gz
Algorithm Hash digest
SHA256 689002a31338ee21137ee0eb8f6aeb8c0fde0c7e90d9440c92acf04309e42ea5
MD5 2f136f12ee4dd9647d68d900c4c65b7a
BLAKE2b-256 b57f66d7faef3c6d1a28e14af531a91fc96d6871adbf72924a8e69db6632a952

See more details on using hashes here.

File details

Details for the file signed_urls-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: signed_urls-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.8

File hashes

Hashes for signed_urls-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4a9d13e26cc20e83f5248c1b9228c818cfc027007632083214f3cb2831bf948
MD5 75e9abaed3a38ad6e41ffb6681dadc4e
BLAKE2b-256 7360505c20512dd4466447813b5713279a2b32fff3933fcd6aca7136c54b3ed6

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