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_ =
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
assert not os.path.isfile("/tmp/file_data/test.txt") # noqa


The different repositories share the next operations:

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


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