superdatabase3000 package

DbServer

class superdatabase3000.DbServer(sock_filename=None, hdf_filename=None)[source]

A server running your favorite database.

Parameters
  • sock_filename (str) – path to the DbServer socket (default: “/tmp/superdatabase3000.sock”)

  • hdf_filename (str) – path to the DbServer hdf store (default: “~/.superdatabase3000.hdf”)

Example

>>> server = DbServer(
...     sock_filename="/tmp/db.sock",
...     hdf_filename="/tmp/db.h5"
... )
>>> server.read_loop()
read_loop()[source]

Poll events in an infinite loop. Check for events on the server.

This will handle:
  • accepting/removing clients

  • sending messages (the ones added to the queue with send_to)

  • reading messages

DbClient

class superdatabase3000.DbClient(sock_filename=None)[source]

A client to interact with your favorite database.

Parameters

sock_filename (str) – path to the DbServer socket (default: “/tmp/superdatabase3000.sock”)

Example

Assuming a server is already launched

>>> client = DbClient("/tmp/db.sock")
>>> df = client.select("/toto")
delete(table, where)[source]

Drop the rows matching the ‘where’ close on the given ‘table’.

Parameters
Returns

bool – False if the table doesn’t exist.

drop(table)[source]

Drop the given ‘table’.

Parameters

table (str) – the name of the table to query

Returns

bool – False if the table doesn’t exist.

insert(table, df)[source]

Insert the DataFrame ‘df’ to the given ‘table’. Might update values.

The table must always be sorted, so you should prefer inserting to the end (with growing indexes) if you need better performances.

Parameters
  • table (str) – the name of the table to query

  • df (DataFrame) – the DataFrame to insert in the database

Returns

bool – False if the table doesn’t exist.

select(table, where=None, columns=None, start=None, stop=None)[source]

Select rows (as a DataFrame) from the given ‘table’.

Parameters
Returns

The selected DataFrame, otherwise None if something funky happens.