otp.databases#
- databases(context=utils.default, derived=False, readable_only=True, fetch_description=None, as_table=False)#
Gets all available databases in the
context
.- Parameters
context (str, optional) – Context to run the query. If not set then default
context
is used. See guide about switching contexts for examples.derived (bool, dict) – If False (default) then derived databases are not returned. Otherwise derived databases names are added to the result after the non-derived databases. If set to dict then its items used as parameters to
derived_databases()
. If set to True then default parameters forderived_databases()
are used.readable_only (bool) – If set to True (default), then return only the databases with read-access for the current user. Otherwise return all databases visible from the current process.
fetch_description (bool) – If set to True, retrieves descriptions for databases and puts them into
description
property ofDB
objects in a returned dict.as_table (bool) – If False (default), this function returns a dictionary of database names and database objects. If True, returns a pandas.DataFrame table where each row contains the info for each database.
- Returns
Dict where keys are database names and values are
DB
objectsor pandas.DataFrame object depending on
as_table
parameter.
- Return type
Union[dict[str, onetick.py.db._inspection.DB], pandas.core.frame.DataFrame]
Examples
Get the dictionary of database names and objects:
>>> otp.databases() {'ABU_DHABI': <onetick.py.db._inspection.DB at 0x7f9413a5e8e0>, 'ABU_DHABI_BARS': <onetick.py.db._inspection.DB at 0x7f9413a5ef40>, 'ABU_DHABI_DAILY': <onetick.py.db._inspection.DB at 0x7f9413a5eac0>, 'ALPHA': <onetick.py.db._inspection.DB at 0x7f9413a5e940>, 'ALPHA_X': <onetick.py.db._inspection.DB at 0x7f9413a5e490>, ... }
Get a table with database info:
>>> otp.databases(as_table=True) Time DB_NAME READ_ACCESS WRITE_ACCESS ... 0 2003-01-01 ABU_DHABI 1 0 ... 1 2003-01-01 ABU_DHABI_BARS 1 1 ... 2 2003-01-01 ABU_DHABI_DAILY 1 1 ... 3 2003-01-01 ALPHA 1 1 ... 4 2003-01-01 ALPHA_X 1 1 ... ... ... ... ... ... ...
See also