pycyphal.application.register.backend.static module

class pycyphal.application.register.backend.static.StaticBackend(location: None | str | Path = None)[source]

Bases: Backend

Register storage backend implementation based on SQLite. Supports either persistent on-disk single-file storage or volatile in-memory storage.

>>> b = StaticBackend("my_register_file.db")
>>> b.persistent    # If a file is specified, the storage is persistent.
True
>>> b.location
'my_register_file.db'
>>> b.close()
>>> b = StaticBackend()
>>> b.persistent    # If no file is specified, the data is kept in-memory.
False
>>> from pycyphal.application.register import Bit
>>> b["foo"] = Value(bit=Bit([True, False, True]))   # Create new register.
>>> b["foo"].mutable
True
>>> list(b["foo"].value.bit.value)
[True, False, True]
>>> b["foo"] = Value(bit=Bit([False, True, True]))  # Set new value.
>>> list(b["foo"].value.bit.value)
[False, True, True]
>>> list(b)
['foo']
>>> del b["foo"]
>>> list(b)
[]
__init__(location: None | str | Path = None)[source]
Parameters:

location – Either a path to the database file, or None. If None, the data will be stored in memory.

The database is always initialized with check_same_thread=False to enable delegating its initialization to a thread pool from an async context. This is important for this library because if one needs to initialize a new node from an async function, calling the factories directly may be unacceptable due to their blocking behavior, so one is likely to rely on asyncio.loop.run_in_executor(). The executor will initialize the instance in a worker thread and then hand it over to the main thread, which is perfectly safe, but it would trigger a false error from the SQLite engine complaining about the possibility of concurrency-related bugs.

property location: str[source]
property persistent: bool[source]
close() None[source]
index(index: int) str | None[source]
setdefault(key: str, default: Entry | Value_1_0 | None = None) Entry[source]
__getitem__(key: str) Entry[source]
__setitem__(key: str, value: Entry | Value_1_0) None[source]

If the register does not exist, it will be implicitly created. If the value is an instance of Value, the mutability flag defaults to the old value or True if none.

__delitem__(key: str) None[source]
__iter__() Iterator[str][source]
__len__() int[source]