pycyphal.application.register.backend.static module

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

Bases: pycyphal.application.register.backend.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.
>>> b.location
>>> b.close()
>>> b = StaticBackend()
>>> b.persistent    # If no file is specified, the data is kept in-memory.
>>> from pycyphal.application.register import Bit
>>> b["foo"] = Value(bit=Bit([True, False, True]))   # Create new register.
>>> b["foo"].mutable
>>> 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)
>>> del b["foo"]
>>> list(b)
__init__(location: Union[None, str, pathlib.Path] = None)[source]

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) Optional[str][source]
setdefault(key: str, default: Optional[Union[pycyphal.application.register.backend.Entry, uavcan.register.Value_1_0.Value_1_0]] = None) pycyphal.application.register.backend.Entry[source]
__getitem__(key: str) pycyphal.application.register.backend.Entry[source]
__setitem__(key: str, value: Union[pycyphal.application.register.backend.Entry, uavcan.register.Value_1_0.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]