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.2rc11.tar.gz
(36.8 kB
view hashes)
Built Distribution
dbrepo-1.4.2rc11-py3-none-any.whl
(26.6 kB
view hashes)
Close
Hashes for dbrepo-1.4.2rc11-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fcf710a02232d0f9c147eb63547f110a80fd1781c36c835e82fa7e1be9dc666 |
|
MD5 | f720f8edb74e059d3b3664170d698c64 |
|
BLAKE2b-256 | 56c09f097aa7729d346cc465410850d2fa2e24c39047a1ae23e8222d7f075001 |