Skip to main content

Tests

file-keeper

Abstraction layer for reading, writing and managing file-like objects.

The package implements drivers for a number of storage types(local filesystem, redis, AWS S3, etc.) and defines a set of tools to simplify building your own drivers for storage you are using.

Read the documentation for a full user guide.

Features

  • Unified API: Consistent interface across multiple storage backends
  • Multiple Storage Backends: Support for file system, memory, S3, GCS, Azure, Redis, and more
  • Type Safety: Comprehensive type annotations for better development experience
  • Security: Built-in protection against directory traversal and other attacks
  • Extensible: Plugin architecture for adding custom storage adapters
  • Comprehensive Testing: Extensive test coverage with security-focused tests

API Overview

Creating Storage

Use make_storage() to create storage instances:

import file_keeper as fk

# Create memory storage for testing
storage = fk.make_storage("sandbox", {"type": "file_keeper:memory"})

# Create filesystem storage
storage = fk.make_storage("fs", {
    "type": "file_keeper:fs",
    "path": "/path/to/files",
    "initialize": True
})

File Operations

# Upload a file
upload = fk.make_upload(b"file content")
result = storage.upload("filename.txt", upload)

# Read file content
content = storage.content(result)

# Check if file exists
exists = storage.exists(result)

# Remove file
removed = storage.remove(result)

Key Functions

  • make_storage(name, settings): Create a storage instance
  • make_upload(data): Create an upload object from data
  • get_storage(name, settings=None): Get or create a named storage instance from the pool

Usage

Initialize storage pointing to /tmp/example folder:

import os
from file_keeper import make_storage

storage = make_storage("sandbox", {
    "type": "file_keeper:fs",
    "path": "/tmp/example",
    # this option creates the folder if it does not exist.
    # Without it storage raises an error if folder is missing
    "initialize": True,
})
assert os.path.isdir("/tmp/example")

Upload file into the storage initialized in the previous step and play with it a bit:

from file_keeper import make_upload
upload = make_upload(b"hello world")

# save the data and verify its presence in the system
result = storage.upload("hello.txt", upload)
assert result.size == 11
assert os.path.isfile("/tmp/example/hello.txt")

# change location of the file
moved_result = storage.move("moved-hello.txt", result, storage)
assert not os.path.exists("/tmp/example/hello.txt")
assert os.path.isfile("/tmp/example/moved-hello.txt")

# read the file
assert storage.content(moved_result) == b"hello world"

# remove the file
storage.remove(moved_result)
assert not os.path.exists("/tmp/example/moved-hello.txt")

Development

Install dev extras:

pip install -e '.[dev]'

Run unittests:

pytest

Run typecheck:

pyright

License

AGPL

Metadata

Release files for file-keeper 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for file-keeper 0.3.0
File Size Uploaded Provenance Actions
file_keeper-0.3.0.tar.gz 67.2 kB Without provenance Details for file_keeper-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for file-keeper 0.3.0
File Interpreter ABI Platform Actions
file_keeper-0.3.0-py3-none-any.whl Python 3 none any Details for file_keeper-0.3.0-py3-none-any.whl

Total release size: 149.8 kB

Release files / file_keeper-0.3.0.tar.gz

Download URL file_keeper-0.3.0.tar.gz
Size 67.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ff6f37506762069d381ebf4f18620de35a7eee8691cb263c81938338dd7058c2
BLAKE2b-256 checksum
How to use checksums
ad8a8e0b40d7097d420092fd429a506cb6f876929fd7b5a5809837989e4d076e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / file_keeper-0.3.0-py3-none-any.whl

Download URL file_keeper-0.3.0-py3-none-any.whl
Size 82.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf757660088521b7db51bb2dc8f421026f792c928ae5ae1dfcdfffc059793163
BLAKE2b-256 checksum
How to use checksums
45fc1ee717947dd969e910706553205e37383c97c012d67af9e13b88027449ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for file-keeper 0.3.0

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.3.0 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