Skip to main content

django-s3-session-storage

A lightweight Django storage backend for Amazon S3 that supports shared boto3.Session reuse and dependency injection —
designed to eliminate latency spikes from repeated IAM credential fetching on every file access.


⚡ Why?

When using django-storages, each new instance of S3Storage internally creates a new boto3.Session.
This triggers fresh IAM credential resolution (via EC2/ECS metadata or STS), which can add tens to hundreds of milliseconds of latency per request —
especially when accessing S3-backed FileField or ImageField objects frequently.

django-s3-session-storage solves this by allowing you to inject or share a single, cached boto3.Session,
so IAM tokens are fetched once and reused across all storage operations.

Result:
✅ Consistent response times
✅ Fewer network round trips to AWS metadata endpoints
✅ Simpler dependency injection for testing and configuration


🚀 Features

  • 🔁 Reuses a shared boto3.Session across all S3 operations
  • ⚙️ Supports dependency injection for clean app design
  • 🧠 Drop-in replacement for storages.backends.s3.S3Storage
  • ⚡ Eliminates repeated IAM token lookups, reducing S3 latency
  • 🧪 Fully tested, type-annotated, and dependency-light

📦 Installation

pip install django-s3-session-storage

or with uv:

uv add django-s3-session-storage

⚙️ Usage

In your Django settings:

import boto3
from django_s3_session_storage import make_storages

BOTO3_SESSION = boto3.Session(region_name="eu-central-1")

STORAGES = {
    "default": make_storages(
        bucket_name="my-bucket",
        region_name="eu-central-1",
        session=BOTO3_SESSION,  # optional
    ),
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    },
}

S3SessionStorage will reuse your provided session,
or lazily create one if none is given.


🧠 Example: Direct instantiation

from django_s3_session_storage import S3SessionStorage
import boto3

session = boto3.Session(region_name="us-east-1")
storage = S3SessionStorage(bucket_name="example-bucket", region_name="us-east-1", session=session)

🧪 Running Tests

uv sync --dev
pytest

Minimal Django settings are auto-configured in tests/conftest.py.


🧰 API Reference

S3SessionStorage

Subclass of storages.backends.s3.S3Storage that reuses an injected or cached boto3.Session.

Constructor:

S3SessionStorage(
    *,
    session: Optional[boto3.Session] = None,
    **kwargs
)
  • session: Optional preconfigured boto3.Session.
    If not provided, one is created lazily from the region_name.

make_storages(bucket_name, region_name, session=None)

Helper for building a single Django STORAGES entry.

Returns:

{
    "BACKEND": "django_s3_session_storage.S3SessionStorage",
    "OPTIONS": { ... }
}

🧾 License

MIT License © 2025 Credibur GmbH
Developed and maintained by the engineering team at Credibur GmbH.


🔗 Links

Metadata

Release files for django-s3-session-storage 0.1.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 django-s3-session-storage 0.1.1
File Size Uploaded Provenance
django_s3_session_storage-0.1.1.tar.gz 5.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-s3-session-storage 0.1.1
File Interpreter ABI Platform
django_s3_session_storage-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.1 kB

Release files / django_s3_session_storage-0.1.1.tar.gz

Download URL django_s3_session_storage-0.1.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
154e906a4c70f0edad9320734c5e2d5682ffc9ec228d68ca06c3d2594277671f
BLAKE2b-256 checksum
How to use checksums
8c28bc32a9007a9b93b3d934a444ef720f5a87c5737bbb168b3006d56edb5b29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release files / django_s3_session_storage-0.1.1-py3-none-any.whl

Download URL django_s3_session_storage-0.1.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f09fe008518c6fbe71d02d9a9a7c60092ec24c35ea062147a3639ae5edefe751
BLAKE2b-256 checksum
How to use checksums
4534070671ed9d92ca23082322dbb9535adb5d0949bd7f9bd5debed6913fa720
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Security for django-s3-session-storage 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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