class litestar.stores.file.FileStore#

Bases: NamespacedStore

File based, thread and process safe, asynchronous key/value store.

__init__(path: PathLike[str]) None#

Initialize FileStorage.


path – Path to store data under


file path

with_namespace(namespace: str) FileStore#

Return a new instance of FileStore, using a sub-path of the current store’s path.

async set(key: str, value: str | bytes, expires_in: int | timedelta | None = None) None#

Set a value.

  • key – Key to associate the value with

  • value – Value to store

  • expires_in – Time in seconds before the key is considered expired



async get(key: str, renew_for: int | timedelta | None = None) bytes | None#

Get a value.

  • key – Key associated with the value

  • renew_for – If given and the value had an initial expiry time set, renew the expiry time for renew_for seconds. If the value has not been set with an expiry time this is a no-op


The value associated with key if it exists and is not expired, else None

async delete(key: str) None#

Delete a value.

If no such key exists, this is a no-op.


key – Key of the value to delete

async delete_all() None#

Delete all stored values.


This deletes and recreates FileStore.path

async delete_expired() None#

Delete expired items.

Since expired items are normally only cleared on access (i.e. when calling get()), this method should be called in regular intervals to free disk space.

async exists(key: str) bool#

Check if a given key exists.

async expires_in(key: str) int | None#

Get the time in seconds key expires in. If no such key exists or no expiry time was set, return None.