Skip to main content

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

Project details


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.3rc2.tar.gz (37.1 kB view hashes)

Uploaded Source

Built Distribution

dbrepo-1.4.3rc2-py3-none-any.whl (27.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page