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 and pika.

Installing

$ python -m pip install dbrepo

This package supports Python 3.11+.

Quickstart

Get public data from a table as pandas DataFrame:

from dbrepo.RestClient import RestClient

client = RestClient(endpoint="https://test.dbrepo.tuwien.ac.at")
# Get a small data slice of just three rows
df = client.get_table_data(database_id="e0d82287-9099-4077-8f69-3c19fc3bc145",
                           table_id="71f8c746-ea26-4651-b3f2-ce46830f1af4",
                           page=0, size=3)
print(df)
#     x_coord         component   unit  ... value stationid meantype
# 0  16.52617  Feinstaub (PM10)  µg/m³  ...  21.0   01:0001      HMW
# 1  16.52617  Feinstaub (PM10)  µg/m³  ...  23.0   01:0001      HMW
# 2  16.52617  Feinstaub (PM10)  µg/m³  ...  26.0   01:0001      HMW
#
# [3 rows x 12 columns]

Create table and import DataFrame into a table:

import pandas as pd
from dbrepo.RestClient import RestClient

client = RestClient(endpoint="https://test.dbrepo.tuwien.ac.at", username="foo",
                    password="bar")
df = pd.DataFrame(data={'x_coord': 16.52617, 'component': 'Feinstaub (PM10)',
                        'unit': 'µg/m³', ...})
df = df.set_index(['x_coord'])
client.create_table(database_id="e0d82287-9099-4077-8f69-3c19fc3bc145",
                    name="Sensor", is_public=True, is_schema_public=True,
                    dataframe=df)

... or just create the table schema by setting create_table(..., withData=False).

In both cases it is important to set the index to existing columns that uniquely identify a row. You can specify multiple columns:

...
df = df.set_index(['some_column', 'some_other_column'])

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://dbrepo1.ec.tuwien.ac.at"
REST_API_USERNAME="foo"
REST_API_PASSWORD="bar"
REST_API_SECURE="True"
AMQP_API_HOST="https://dbrepo1.ec.tuwien.ac.at"
AMQP_API_PORT="5672"
AMQP_API_USERNAME="foo"
AMQP_API_PASSWORD="bar"
AMQP_API_VIRTUAL_HOST="dbrepo"

You can disable logging by setting the log level to e.g. INFO:

from dbrepo.RestClient import RestClient
import logging
logging.getLogger().setLevel(logging.INFO)
...
client = RestClient(...)

Roadmap

  • Searching

Contact

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.10.5.tar.gz (98.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbrepo-1.10.5-py3-none-any.whl (83.8 kB view details)

Uploaded Python 3

File details

Details for the file dbrepo-1.10.5.tar.gz.

File metadata

  • Download URL: dbrepo-1.10.5.tar.gz
  • Upload date:
  • Size: 98.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for dbrepo-1.10.5.tar.gz
Algorithm Hash digest
SHA256 1fb55b6c2b1573a44bf203d6fdcba4de1a41b9b2e9f9ac3e35b1d45e76aa3b4e
MD5 7ab6a952f5dda09193a35431a00f25a7
BLAKE2b-256 3092716f18b6193dbfe66ad54f6a89a0bcea1dff6cf0b0eecde990bde2d6836d

See more details on using hashes here.

File details

Details for the file dbrepo-1.10.5-py3-none-any.whl.

File metadata

  • Download URL: dbrepo-1.10.5-py3-none-any.whl
  • Upload date:
  • Size: 83.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for dbrepo-1.10.5-py3-none-any.whl
Algorithm Hash digest
SHA256 72572de7fe8cec856d728586c7995b3fa35dc99f7c224e1ca651eb91ab9f0ef2
MD5 d619c55d90a9a8d3fb14bd011717a3ea
BLAKE2b-256 14f7d954870edce5da1f9c5429ccbaf801cc3f816a9aa5d04849dce83930403f

See more details on using hashes here.

Supported by

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