Skip to main content

Abstraction level for object storages.

Project description

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

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

file_keeper-0.1.1.tar.gz (53.5 kB view details)

Uploaded Source

Built Distribution

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

file_keeper-0.1.1-py3-none-any.whl (68.7 kB view details)

Uploaded Python 3

File details

Details for the file file_keeper-0.1.1.tar.gz.

File metadata

  • Download URL: file_keeper-0.1.1.tar.gz
  • Upload date:
  • Size: 53.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for file_keeper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5024109def68ce7bc5351d7a82e8fbbfec08d86a5b88f7400c14fd06ce3c7c5f
MD5 6a173bb04e8a09c9db7df8296cffb9b0
BLAKE2b-256 fdef359c929973608d0ba739df120e25b5ec728afdd92a7d96087799f255ee3d

See more details on using hashes here.

File details

Details for the file file_keeper-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: file_keeper-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 68.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.16

File hashes

Hashes for file_keeper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 11b5ed316593339b87ac3d153f6d2bcd7fe0c0696716ba4058839f0309a7fcbd
MD5 c2e2d06ce0f95565d93ecfa30260dab7
BLAKE2b-256 d68eb272dd93845cf391217abe6fd6a1237f926a019ff3c84adc36bb26fee4be

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