Python class helpers for sqlite3 and InfluxDB databases.
SQHelper (SqLite3 Databases)
Example: Create, read and remove a table working with just dataframes.
from dbops.sqhelper import SQHelper
import pandas as pd
>>> table_name = 'temperature'
>>> df = pd.DataFrame({"timestamp": [1587222785, 1587222786], 'celsius': [23.3, 23.9]})
>>> db = 'myDatabase.sql3'
>>> database = SQHelper(db)
# The dataframe column names are used for the table's column names.
# All dataframe entries are automatically inserted.
>>> database.create_table(table_name,df)
['timestamp', 'celsius']
# Add some more entries to the database, in this case duplicates of the above entry are made.
>>> database.insert(table_name,df)
True
# Read the content back into a dataframe
>>> database.table_to_df(table_name)
celsius timestamp
0 34.2 1587222785
1 23.3 1587222785
2 23.9 1587222786
3 23.3 1587222785
4 23.9 1587222786
# Remove the table from the database
>>> database.remove_table(table_name);
True
Example: Create a table, add an entry and return it as a Pandas dataframe.
from dbops.sqhelper import SQHelper
>> db = 'myDatabase.sql3'
>>> table_name = 'temperature'
>>> columns = {'timestamp': 'NUMERIC', 'celsius': 'REAL'}
# Create a class instance for a single database
>>> database = SQHelper(db)
# Add a table to the database
>>> database.create_table(table_name,columns)
['timestamp', 'celsius']
# Get all the tables in the database
>>> database.get_table_names()
['temperature']
# Add an entry to the database
>>> new_entry = {'timestamp': 1587222785, 'celsius': 34.2}
>>> database.insert(table_name, new_entry)
True
# Return the table as a Pandas Dataframe
df = database.table_to_df(table_name)
# Return all rows based on a column query, returns matching rows as dataframe
>>> database.get_row(table_name, 'celsius', 34.2);
celsius timestamp
0 34.2 1587222785
Use help(SQHelper) for more detailed information.
InfluxDB
from dbops.imfluxhelper import InfluxHelper
# Create a class instance for a single database
>>> database = InfluxHelper('database_name')
# Check the database is connected to OK
>>> database.exists()
True
# Add a new measurement to the database as a dictionary
>>> data = {'timestamp': 1585848415, 'temperature': 23.3, 'humidity': 12.2, 'room': 'kitchen', 'house': 'home'}
>>> measurement = 'Environment'
>>> fields = ['temperature', 'humidity']
>>> tags = ['room', 'house']
>>> database.insert(measurement, data, field_keys=fields, tag_keys=tags, use_timestamp=True)
True
# Add multiple measurements as a Pandas DataFrame
>>> data = [{
'timestamp': 1585848415,
'temperature': 23.3,
'humidity': 12.2,
'room': 'kitchen',
'house': 'home'
}, {
'timestamp': 1585848416,
'temperature': 22.1,
'humidity': 13.4,
'room': 'bedroom',
'house': 'home'
}]
>>> df = pd.DataFrame(data)
>>> measurement = 'Household'
>>> fields = ['temperature', 'humidity']
>>> tags = ['room', 'house']
>>> database.insert(measurement, df, field_keys=fields, tag_keys=tags, use_timestamp=use_time)
True
# Get all the measurements in the database
>>> database.get_measurement_names()
['Environment', 'Household']
# Get the last time based entry in a table
>>> last_time_entry = database.get_last_time_entry('Household', 'humidity', 'room', 'bedroom', as_unix=True)
>>> last_time_entry['last']
13.4
>>> last_time_entry['time']
1585848416
Use help(InfluxHelper) for more detailed information.
Version History
0.1.0:
- Added interface for Influx Databases
- Added some timestamp conversion utilities
- Improved documentation
Metadata
Release files for db-ops 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| db-ops-0.1.1.tar.gz | 9.1 kB | Without provenance | Details for db-ops-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| db_ops-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for db_ops-0.1.1-py3-none-any.whl |
Total release size: 19.9 kB
Release files / db-ops-0.1.1.tar.gz
| Download URL | db-ops-0.1.1.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4d215429b4869f82fa6682d3ae392d928814b8cbc0fb7c0a8b0802a5f2ec45e
|
|
BLAKE2b-256 checksum How to use checksums |
7631865304c09b2ff920d19ccad476c012e75284eac1788d95817cba48471e2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Release files / db_ops-0.1.1-py3-none-any.whl
| Download URL | db_ops-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d325294667e11e674f1dc3f3e06c9ae91948225e02a82913426cb2511eb4a9e
|
|
BLAKE2b-256 checksum How to use checksums |
a263059fa266d6e8f6e9214992967dbf74711467237937cba44a4177110928f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Security for db-ops 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.