PortableTab.capnp_manager module

class PortableTab.capnp_manager.CapnpManager(db_dir)

Bases: object

Class that manages the Capnp schema.

Parameters:

db_dir (Path-like) – Base directory where the schema and tables are placed.

page_cache

PageReader cache. Up to 10 caches are retained.

Type:

OrderedDict

PAGE_SIZE = 500000
get_page_mmap(page_path: Path) mmap

Get mmap object assigned to the page file.

Parameters:

page_path (Path-like) – Path to the page file.

Notes

  • This method uses cache mechanism. If more than 10 objects are opened, the oldest one is released.

classmethod load_schema(path: str, as_module: str | None = None) Any

Load capnp schema into the name space.

Parameters:
  • path (str) – Path to the schema file.

  • as_module (str, optional) – Name of the module assinged to the schema.

Returns:

The assigned module.

Return type:

pycapnp.module

Notes

  • The type of the assigned module is dynamically determined from the file name.

modules = {}
unload() None

Release loaded resources manually, including cached PageReaders.

classmethod unload_schema(names: List[str] | None = None) None

Unload capnp schema from the name space.

Parameters:

names ([str], optional) – List of assigned names for the modules to be unloaded.

class PortableTab.capnp_manager.PageReader(page_path: Path)

Bases: object

Class that manages a mmapped page file.

Paramaters

page_path: Pathlike

Path to the page file.

fp

File object to read the file contents.

Type:

File object

mm

Mmap object to map the file to memory.

Type:

Memory-map object