Skip to main content

Keg-Storage

nox codecov

Keg-Storage provides a common interface for storing files on the local filesystem, Amazon S3, Azure Blob Storage, or an SFTP server. It can be used directly or configured as a Flask/Keg extension with multiple named storage profiles.

Installation

Install the base package for local filesystem storage:

pip install KegStorage

Install the extra for each remote backend you use:

Backend or integration Extra Install command
Amazon S3 aws pip install "KegStorage[aws]"
Azure Blob Storage azure pip install "KegStorage[azure]"
SFTP sftp pip install "KegStorage[sftp]"
Flask/Keg helpers keg pip install "KegStorage[keg]"

Keg-Storage requires Python 3.12 or newer.

Usage

All backends implement the same operations, including list, open, upload, download, copy, delete, and link_to where supported.

This example uses the local filesystem backend:

from io import BytesIO
from pathlib import Path

from keg_storage import LocalFSStorage


storage_root = Path("var/storage")
storage_root.mkdir(parents=True, exist_ok=True)

storage = LocalFSStorage(root=storage_root, name="local")
storage.upload(BytesIO(b"Hello from Keg-Storage!"), "examples/hello.txt")

download = BytesIO()
storage.download("examples/hello.txt", download)
assert download.getvalue() == b"Hello from Keg-Storage!"

Flask and Keg integration

Configure one or more named profiles and initialize the extension using the standard Flask extension pattern:

from pathlib import Path

from flask import Flask
from keg_storage import LocalFSStorage, Storage


storage = Storage()


def create_app():
    app = Flask(__name__)
    storage_root = Path("var/storage")
    storage_root.mkdir(parents=True, exist_ok=True)
    app.config["KEG_STORAGE_PROFILES"] = [
        (
            LocalFSStorage,
            {
                "name": "local",
                "root": storage_root,
            },
        ),
    ]
    storage.init_app(app)
    return app

Within an application context, retrieve a configured backend by name:

backend = storage.get_interface("local")
backend.put("report.pdf", "reports/report.pdf")

The first configured profile is used when get_interface() is called without a name. Initializing the extension also adds a storage command group to the Flask CLI:

flask storage --location local list .
flask storage --location local put report.pdf reports/report.pdf
flask storage --location local get reports/report.pdf

See the documentation for backend configuration, temporary upload/download links, and the StorageOperations helper for Flask views.

Development

Copier template

Project structure and tooling mostly derive from Coppy. See its documentation for context and additional instructions. Update this project by following Coppy's template update instructions.

Project setup

  1. Install the host dependencies.
  2. Run uv sync.
  3. Install the hooks with prek install.
  4. Run the checks with nox.

Versions

Use mise run version show to show the current version and mise run version bump to create a version commit and tag.

Metadata

Release files for KegStorage 0.20261120.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 KegStorage 0.20261120.1
File Size Uploaded Provenance Actions
kegstorage-0.20261120.1.tar.gz 171.9 kB With provenance Details for kegstorage-0.20261120.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for KegStorage 0.20261120.1
File Interpreter ABI Platform Actions
kegstorage-0.20261120.1-py3-none-any.whl Python 3 none any Details for kegstorage-0.20261120.1-py3-none-any.whl

Total release size: 200.1 kB

Release files / kegstorage-0.20261120.1.tar.gz

Download URL kegstorage-0.20261120.1.tar.gz
Size 171.9 kB
Tags Source
SHA-256 checksum
How to use checksums
10c3023042829edebad5657672dbc0dcd26df25af51dcad68c899820853862c5
BLAKE2b-256 checksum
How to use checksums
aa4cd82f28d7281ee5b9db94deea8dbf9e9271c34e36ccd2b5367cd38c1344a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / kegstorage-0.20261120.1-py3-none-any.whl

Download URL kegstorage-0.20261120.1-py3-none-any.whl
Size 28.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
97452b6e9e74a083590e5802e436b12d2ca147b0203745cd52db80f222db4315
BLAKE2b-256 checksum
How to use checksums
5551156b75da33794563c99c467cb6e2cdbdf5f78f39776adb4ffa5d85b1e9e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for KegStorage 0.20261120.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for kegstorage-0.20261120.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

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.

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