title | description | date | author | tags |
---|---|---|---|---|
Load an existing database |
How to load an existing database into a Python process |
July 2024 |
KX Systems, Inc., |
PyKX, q, database, loading |
This page explains how to load an existing database into a Python process.
!!! tip "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 #!python 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 #!python load
command as shown below:
>>> import pykx as kx
>>> db = kx.DB()
>>> db.tables
>>> db.load('/tmp/db')
>>> db.tables
['quote', 'trade']
To overwrite the database loaded and use another database if needed, use the #!python overwrite
keyword.
In the below example, we are loading a new database #!python /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)
- Modify the contents of your database.
- Query your database with Python.
- Compress/encrypt data for persisting database partitions.