data_basedbopendbopen

dbopen

class data_base.dbopen.dbopen(path, mode='r')

Context manager to open files in databases

This explicitly calls Python’s open() method on a file. This is generally not recommended, as the content of databases is usually written in a specific format, that is automatically inferred by the database.

However, for development and testing purposes, it may be of use to explicitly open these files.

Example

>>> with dbopen('db://my_db/my_key') as f:
...     print(f.read())
# dumps the raw file content - not recommended for e.g. binary formats
Parameters:
  • path (str) – The path to the file.

  • mode (str) – The mode in which the file is opened. Default: ‘r’

Attributes:

path

The path to the file.

Type:

str

mode

The mode in which the file is opened.

Type:

str

exit_hooks

A list of functions to be called when the context manager is exited. Used to close .tar files

Type:

list