Skip to content

File Repositories

File repositories give a common interface to store computer file contents.

They only persist the content of File objects into the different backends. The metadata however is not stored, so you'll need to use a data repository for that.

A Simple Example

import os

from repository_orm import File, load_file_repository

repo = load_file_repository("local:/tmp/file_data")

file_ = File(path="test.txt")
file_._content = "File content"

# Save content in the repository

file_ = repo.save(file_)
assert file_.path == "/tmp/file_data/test.txt"
assert os.path.isfile(file_.path)

# Load the content from the repository
file_ = File(path="test.txt")
file_ = repo.load(file_)
assert file_.content == "File content"

# Remove the file content from the repository
repo.delete(file_)
assert not os.path.isfile("/tmp/file_data/test.txt") # noqa

Usage

The different repositories share the next operations:

load
Load the content of the file from the persistence system.
save
Save the content of the file into the persistence system.
delete
Delete the file from the persistence system.

Repositories

To change the repository you only need to change the url passed to load_file_repository. We have the next repositories:


Last update: 2021-12-02