Skip to content

Load an existing database

This page explains how to load an existing database into a Python process.

Tip: For the best experience, we recommend reading Databases in PyKX and generate a database first.

By default, you can only load one database into a Python process when using PyKX. To automatically load a database when initializing the pykx.DB class, set the database location as the path:

>>> import pykx as kx
>>> db = kx.DB(path='/tmp/db')
>>> db.tables
['quote', 'trade']

To load a database after initialization, use the load command as shown below:

>>> import pykx as kx
>>> db = kx.DB()
>>> db.tables
>>> db.load('/tmp/db')
>>> db.tables
['quote', 'trade']

Change the loaded database

To overwrite the database loaded and use another database if needed, use the overwrite keyword.

In the below example, we are loading a new database /tmp/newdb which in our case doesn't exist but mimics the act of loading a separate database:

>>> db = kx.DB(path='/tmp/db')
>>> db.load(path='/tmp/newdb', overwrite=True)

Next Steps