DBRepo Python Library
Project description
DBRepo Python Library
Official client library for DBRepo, a database repository to support research based on requests, pydantic, tuspy and pika.
Installing
$ python -m pip install dbrepo
This package supports Python 3.11+.
Quickstart
Create a table and import a .csv file from your computer.
from dbrepo.RestClient import RestClient
from dbrepo.api.dto import CreateTableColumn, ColumnType, CreateTableConstraints
client = RestClient(endpoint='https://test.dbrepo.tuwien.ac.at', username="foo",
password="bar")
# analyse csv
analysis = client.analyse_datatypes(file_path="sensor.csv", separator=",")
print(f"Analysis result: {analysis}")
# -> columns=(date=date, precipitation=decimal, lat=decimal, lng=decimal), separator=,
# line_termination=\n
# create table
table = client.create_table(database_id=1,
name="Sensor Data",
constraints=CreateTableConstraints(
checks=['precipitation >= 0'],
uniques=[['precipitation']]),
columns=[CreateTableColumn(name="date",
type=ColumnType.DATE,
dfid=3, # YYYY-MM-dd
primary_key=True,
null_allowed=False),
CreateTableColumn(name="precipitation",
type=ColumnType.DECIMAL,
size=10,
d=4,
primary_key=False,
null_allowed=True),
CreateTableColumn(name="lat",
type=ColumnType.DECIMAL,
size=10,
d=4,
primary_key=False,
null_allowed=True),
CreateTableColumn(name="lng",
type=ColumnType.DECIMAL,
size=10,
d=4,
primary_key=False,
null_allowed=True)])
print(f"Create table result {table}")
# -> (id=1, internal_name=sensor_data, ...)
client.import_table_data(database_id=1, table_id=1, file_path="sensor.csv", separator=",",
skip_lines=1, line_encoding="\n")
print(f"Finished.")
Supported Features & Best-Practices
- Manage user account (docs)
- Manage databases (docs)
- Manage database access & visibility (docs)
- Import dataset (docs)
- Create persistent identifiers (docs)
- Execute queries (docs)
- Get data from tables/views/subsets
Configure
All credentials can optionally be set/overridden with environment variables. This is especially useful when sharing
Jupyter Notebooks by creating an invisible .env
file and loading it:
REST_API_ENDPOINT="https://test.dbrepo.tuwien.ac.at"
REST_API_USERNAME="foo"
REST_API_PASSWORD="bar"
REST_API_SECURE="True"
AMQP_API_HOST="https://test.dbrepo.tuwien.ac.at"
AMQP_API_PORT="5672"
AMQP_API_USERNAME="foo"
AMQP_API_PASSWORD="bar"
AMQP_API_VIRTUAL_HOST="/"
REST_UPLOAD_ENDPOINT="https://test.dbrepo.tuwien.ac.at/api/upload/files"
Roadmap
- Searching
Contact
- Prof. Andreas RauberTU Wien
- DI. Martin WeiseTU Wien
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dbrepo-1.4.2rc13.tar.gz
(37.0 kB
view hashes)
Built Distribution
dbrepo-1.4.2rc13-py3-none-any.whl
(27.0 kB
view hashes)
Close
Hashes for dbrepo-1.4.2rc13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7f0e3004e75abb043dad65988d95da29ceaf346408bd8d04773cfdf8e07c2bd |
|
MD5 | 6c4eb01d8224a09aa35f23b49caf2baf |
|
BLAKE2b-256 | cab8641eda96e2da91ab182c0a19edc2191bf15104aa2c7e23b544f1300c2773 |