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.

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.0a0.tar.gz (36.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.0a0-py3-none-any.whl (47.3 kB view details)

Uploaded Python 3

File details

Details for the file file_keeper-0.1.0a0.tar.gz.

File metadata

  • Download URL: file_keeper-0.1.0a0.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.3

File hashes

Hashes for file_keeper-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 a49adaf8fa79794949628ad5ceb1fd9f964b6c2092d8e44aaece4705caf6f181
MD5 9def3cf9f9d637d6fd5c4689c7e6b54e
BLAKE2b-256 cec49de3fce705ac90c696279cd349bc158390b5de6e58ecca8020ddb8613b51

See more details on using hashes here.

File details

Details for the file file_keeper-0.1.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for file_keeper-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb43e1906f6ae9267b722fd0d35f8e8b2969675c6d085b727974ef0d672f37bd
MD5 60aa56c73744f1a44c5589c3cf90eb02
BLAKE2b-256 b242e978bac65ebf17de2d257992774d641ca97c37b30b95acb7f7cbf385b1fa

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