Skip to main content

A simple library for creating CloudFront signatures

Project description

CFSign

A Python library for generating AWS CloudFront signed URLs and cookies. This library provides a simple interface for creating signed URLs and cookies for CloudFront private content.

Installation

Using pip:

pip install cfsign

Using Poetry:

poetry add cfsign

Usage

Basic Configuration

import cfsign

# Configure with your CloudFront key pair
cfsign.configure(
    key_pair_id="YOUR_KEY_PAIR_ID",
    private_key="YOUR_PRIVATE_KEY"
)

Creating Signed URLs/Cookies

from cfsign.signature.cloudfront_signature import CloudfrontSignature

# Create a signature for a specific resource
signature = CloudfrontSignature("https://example.cloudfront.net/private/content.mp4")

# Get signed cookies
cookies = signature.cookie_dict
print(cookies)
"""
Gets you something like:
{
    "CloudFront-Policy": {...},
    "CloudFront-Signature": {...},
    "CloudFront-Key-Pair-Id": {...},
}
"""


# Get query string parameters for signed URLs
query_string = signature.query_string
print(query_string)
# prints - Policy&={...}&Signature={...}&Key-Pair-Id={...}

Example: Using with Requests

import requests

# Using signed cookies
response = requests.get(url, cookies=signature.cookie_dict)

# Using signed URL
signed_url = f"{url}?{signature.query_string}"

# You could also use the built-in signed url if you're not using a wildcard for the resource:
signed_url = signature.signed_url

response = requests.get(signed_url)

Features

  • Generate CloudFront signed URLs
  • Generate CloudFront signed cookies
  • Support for custom policies
  • RSA signing with PKCS1v15 padding and SHA1 hashing (AWS CloudFront standard)
  • Base64 policy encoding/decoding

Development

Setting up Development Environment

  1. Clone the repository
  2. Install development dependencies:
uv sync

Running Tests

# Set PYTHONPATH to project root
pytest

VSCode Configuration

To run tests in VSCode, create a .env file in your project root:

PYTHONPATH=.

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

cfsign-0.0.3.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

cfsign-0.0.3-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file cfsign-0.0.3.tar.gz.

File metadata

  • Download URL: cfsign-0.0.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.8

File hashes

Hashes for cfsign-0.0.3.tar.gz
Algorithm Hash digest
SHA256 05765650e0640bf13274cf1da1c8257ce1e1271f63d70bc0847068b88e7558f0
MD5 ff21bc921303b680ffd363f557b332ad
BLAKE2b-256 c4c3c8e546be38a60aa3fe7e449ab23131b21dae5dee985978f3292ced34c361

See more details on using hashes here.

File details

Details for the file cfsign-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: cfsign-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.8

File hashes

Hashes for cfsign-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1744c71b60ab7fcd1e28d6a7b3efca2c1e8667096151d3f482cf6c9d35d20b72
MD5 c0159bf13b46b435b507d14717656eb9
BLAKE2b-256 a26e1ee99320f460a68cbccff288ec5099348333fc5e0431a45a78e23274fc0c

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