Skip to main content

High-performance library for generating AWS S3 presigned URLs

Project description

Libpresign

Single-purpose library created for generating AWS S3 presigned URLs fast.

Implemented in C++ using OpenSSL 3.1.

Moto

Boto3 is heavy dependency if you just want to create a presigned URL. And it's famously slow.

How to use

import libpresign

libpresign.get(
    "AWS_ACCESS_KEY_ID",
    "AWS_SECRET_ACCESS_KEY",
    "region-1",
    "bucket-name", 
    "object-key.txt",
    3600,  # Expiration time in seconds
)

Output

'https://bucket.s3.amazonaws.com/object-key.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=creds1%2F20230711%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20230711T125101Z&X-Amz-Expires=3600&X-Amz-SignedHeaders=host&X-Amz-Signature=5c5a2e2858261266db950e4912fb12ffcd5d0bcf40d873bf9fe209ee789f6c86'

Example with MinIO or custom S3-compatible endpoint

import libpresign

# For MinIO or other S3-compatible services
libpresign.get(
    "minioadmin",
    "minioadmin",
    "us-east-1",
    "bucket-name", 
    "object-key.txt",
    3600,
    "localhost:9000"  # MinIO endpoint
)

Function signature

def get(
    access_key_id: str,
    secret_access_key: str,
    region: Optional[str],  # defaults to "us-east-1"
    bucket: str,
    key: str,
    expires: Optional[int], # defaults to 3600 (1h)
    endpoint: Optional[str], # defaults to "s3.amazonaws.com"
):
    ...

Comparison to boto3

Test case

Generate 10 000 presigned URLs. Compare execution times

Results

┌────────────────────────┬────────┬────────────┐
│ library                │ boto3  │ libpresign │
├────────────────────────┼────────┼────────────┤
│ avg execution time, μs │ 2232.3 │ 13.9       │ 
└────────────────────────┴────────┴────────────┘

Libpresign came out to be 160 times faster

Dependencies

  • C++ Compiler (GCC, Clang, or MSVC)
  • CMake 3.15+
  • OpenSSL 3.x
  • Python 3.8+ (for Python bindings)

Building from Source

Using CMake (Recommended)

# Create build directory
mkdir build && cd build

# Configure
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build .

# Install (optional)
cmake --install .

CMake Options

  • BUILD_PYTHON_MODULE (ON/OFF): Build Python extension module (default: ON)
  • BUILD_SHARED_LIB (ON/OFF): Build standalone shared library (default: OFF)
  • BUILD_STATIC_LIB (ON/OFF): Build standalone static library (default: OFF)

Building Python Wheels

# Using CMake-based setup
python setup_cmake.py bdist_wheel

# Or use the convenience script
./build-wheels-cmake.sh

Legacy Build Method

The original setuptools-based build is still available:

python setup.py build_ext --inplace

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.1.1.tar.gz (10.5 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: libpresign-1.1.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for libpresign-1.1.1.tar.gz
Algorithm Hash digest
SHA256 2976bc9ea61409422da13293a785cebd1f5b0c8e38c6e5475ba585ff767d54d9
MD5 08f7cd5627a79c8013b3fafb71ff42d0
BLAKE2b-256 5291501baacf077cc186961a61c28781472165020d01f67738e924fa5dce1834

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