Skip to main content

High-performance library for generating AWS S3 presigned URLs

Project description

libpresign

CI PyPI Python Versions License Downloads

High-performance library for generating AWS S3 presigned URLs. Generate presigned URLs up to 160x faster than boto3.

Features

  • 🚀 Lightning Fast: 5-160x faster than boto3 for presigned URL generation
  • 🔐 Secure: Full AWS Signature Version 4 compliance
  • 🌍 Compatible: Works with S3 and S3-compatible services (MinIO, Wasabi, etc.)
  • 📦 Lightweight: Minimal dependencies, pure C++ implementation
  • 🐍 Python Ready: Simple Python bindings with type hints
  • 🧵 Thread Safe: Generate URLs concurrently without locks
  • 💰 Cost Effective: Reduce compute costs with faster operations

Installation

pip install libpresign

Pre-built wheels are available for:

  • Linux: x86_64, aarch64 (Python 3.8-3.13)
  • macOS: x86_64, arm64 (Python 3.8-3.13)
  • Windows: AMD64 (Python 3.8-3.13)

Quick Start

import libpresign

# Generate a presigned URL
url = libpresign.get(
    access_key_id="AKIAIOSFODNN7EXAMPLE",
    secret_access_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
    region="us-east-1",
    bucket="my-bucket",
    key="path/to/file.jpg",
    expires=3600  # URL valid for 1 hour
)

print(url)
# https://my-bucket.s3.us-east-1.amazonaws.com/path/to/file.jpg?X-Amz-Algorithm=...

Performance

Benchmark Results

Generate 10,000 presigned URLs:

Library Time (ms) URLs/sec Speedup
libpresign 60 166,667 160x
boto3 9,600 1,042 1x

Single URL generation:

Library Time (μs) Memory
libpresign 6 262 bytes
boto3 102 1.6 KB

Usage Examples

Basic Usage

import libpresign

# Simple URL generation
url = libpresign.get(
    access_key_id="your-access-key",
    secret_access_key="your-secret-key",
    region="us-east-1",
    bucket="my-bucket",
    key="document.pdf"
)

Custom Endpoint (MinIO/S3-Compatible)

# Use with MinIO or other S3-compatible storage
url = libpresign.get(
    access_key_id="minioadmin",
    secret_access_key="minioadmin",
    region="us-east-1",
    bucket="my-bucket",
    key="file.txt",
    expires=3600,
    endpoint="https://minio.example.com"
)

Batch Generation

# Generate multiple URLs efficiently
config = {
    "access_key_id": "your-access-key",
    "secret_access_key": "your-secret-key",
    "region": "us-west-2",
    "bucket": "my-bucket",
    "expires": 3600
}

urls = []
for i in range(1000):
    url = libpresign.get(**config, key=f"file_{i}.jpg")
    urls.append(url)

Integration with Web Frameworks

FastAPI

from fastapi import FastAPI
import libpresign

app = FastAPI()

@app.get("/presigned-url")
async def get_presigned_url(file_key: str):
    url = libpresign.get(
        access_key_id="...",
        secret_access_key="...",
        region="us-east-1",
        bucket="uploads",
        key=file_key,
        expires=3600
    )
    return {"url": url}

Django

from django.http import JsonResponse
import libpresign

def download_file(request, file_id):
    url = libpresign.get(
        access_key_id=settings.AWS_ACCESS_KEY_ID,
        secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
        region=settings.AWS_REGION,
        bucket=settings.S3_BUCKET,
        key=f"files/{file_id}",
        expires=300  # 5 minutes
    )
    return JsonResponse({"download_url": url})

API Reference

libpresign.get()

Generate a presigned URL for S3 object access.

Parameters:

  • access_key_id (str): AWS access key ID
  • secret_access_key (str): AWS secret access key
  • region (str | None): AWS region (defaults to "us-east-1")
  • bucket (str): S3 bucket name
  • key (str): S3 object key
  • expires (int): URL expiration time in seconds (defaults to 3600)
  • endpoint (str | None): Custom S3 endpoint URL

Returns:

  • str: Presigned URL

Raises:

  • SystemError: If required parameters are invalid

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/myk0la-b/libpresign.git
cd libpresign

# Install uv package manager
curl -LsSf https://astral.sh/uv/install.sh | sh

# Create virtual environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in editable mode with dev dependencies
uv pip install -e ".[dev]"

Running Tests

# Run all tests with coverage
uv run pytest

# Run specific test file
uv run pytest tests/test_basic.py

# Run benchmarks
uv run pytest tests/test_benchmark_boto3.py -v

Code Quality

# Format code
uv run ruff format .

# Lint code
uv run ruff check .

# Type checking
uv run mypy libpresign

Building from Source

Prerequisites

  • C++ compiler with C++11 support
  • CMake 3.15+
  • OpenSSL 3.x
  • Python 3.8+

Build Instructions

# Quick build
pip install .

# Development build
pip install -e .

# Build wheel
pip wheel . --no-deps

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Reporting Issues

If you find a bug or have a feature request, please open an issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with OpenSSL for cryptographic operations
  • Inspired by the need for faster S3 presigned URL generation
  • Thanks to all contributors

Links

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

libpresign-1.2.0.tar.gz (61.0 kB view details)

Uploaded Source

Built Distributions

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

libpresign-1.2.0-cp38-abi3-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.8+Windows x86-64

libpresign-1.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

libpresign-1.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (890.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

libpresign-1.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (901.6 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

libpresign-1.2.0-cp38-abi3-macosx_14_0_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8+macOS 14.0+ x86-64

libpresign-1.2.0-cp38-abi3-macosx_14_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.8+macOS 14.0+ ARM64

File details

Details for the file libpresign-1.2.0.tar.gz.

File metadata

  • Download URL: libpresign-1.2.0.tar.gz
  • Upload date:
  • Size: 61.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for libpresign-1.2.0.tar.gz
Algorithm Hash digest
SHA256 1448eb8c9aea00b5b439b2b9c1ce48b88bded5abc216498cab0fb9a8edb2ca84
MD5 2a45d6c535af2b8fd8b99bbab261dff2
BLAKE2b-256 8fcc45cf9ad3a64f5c080de2d5768594662cf685876dcb8f6913293ecd8a84e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for libpresign-1.2.0.tar.gz:

Publisher: wheels.yml on myk0la-b/libpresign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libpresign-1.2.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: libpresign-1.2.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for libpresign-1.2.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e75daa999490aff6301ad12bd09eba9755398175fee8cb6f016ae1b0d0337d4f
MD5 0651641de1f4c69f86330afe851bd1c9
BLAKE2b-256 17939410f77dad164ccd0b1c3a6631321e0348a457a79dfaac48dd32c4b94f08

See more details on using hashes here.

Provenance

The following attestation bundles were made for libpresign-1.2.0-cp38-abi3-win_amd64.whl:

Publisher: wheels.yml on myk0la-b/libpresign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libpresign-1.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for libpresign-1.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a42bf6485b8719b7213ed1ba1b59489b512aca5cd4b378eb595816d620cd643f
MD5 9f5c2a78a3a94b347dc01370a61e7471
BLAKE2b-256 759de4d2e2c9d627f680d214b465f2500bd4104f0c1dec048703054079dc0184

See more details on using hashes here.

Provenance

The following attestation bundles were made for libpresign-1.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on myk0la-b/libpresign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libpresign-1.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for libpresign-1.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 bf11e7014e13f88a23307474ec178f305f93d0bc117b203de19acb9bb143e206
MD5 47d4a5fd45e41e24d32ecc54c5773a51
BLAKE2b-256 3dae670e1b1983a635e3f6271ad29e04826469c1291472e0915534f0f44f43a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for libpresign-1.2.0-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: wheels.yml on myk0la-b/libpresign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libpresign-1.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for libpresign-1.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cb6e40a472663ed354cd9037207bbad919b948b90fe878f049ef9fa23059d684
MD5 0ec845c3306cb70ac8ba50f9372fedc4
BLAKE2b-256 7caf1f84a73a69ecec6382bd0f4fc79848a18cdb2c4c3eb382260d53c5de6936

See more details on using hashes here.

Provenance

The following attestation bundles were made for libpresign-1.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: wheels.yml on myk0la-b/libpresign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libpresign-1.2.0-cp38-abi3-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for libpresign-1.2.0-cp38-abi3-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 b98a4e756700f6525a58d760981ae8dc700d7ce7b1226b05de1efac14aa676f9
MD5 4b5afc26d793ca5228cd2955f9bf0aa4
BLAKE2b-256 66e1f1e340ea2574d1b5d16d4609627fc57e0936a11b7983ca654bc23022854f

See more details on using hashes here.

Provenance

The following attestation bundles were made for libpresign-1.2.0-cp38-abi3-macosx_14_0_x86_64.whl:

Publisher: wheels.yml on myk0la-b/libpresign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libpresign-1.2.0-cp38-abi3-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for libpresign-1.2.0-cp38-abi3-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c7edacd9dfd6fbd52bc9f94a29a3f39b4d44a8d2c350ae7e021a763194f1f10a
MD5 1329a211642370887766e456780ba304
BLAKE2b-256 e2c371c26abf204a14aa539c2361f469c100540690e42e3fe0bf11457442394f

See more details on using hashes here.

Provenance

The following attestation bundles were made for libpresign-1.2.0-cp38-abi3-macosx_14_0_arm64.whl:

Publisher: wheels.yml on myk0la-b/libpresign

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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