Skip to content
Snippets Groups Projects
Select Git revision
  • cc9a31389371de192cee7b034c49a66df38bba65
  • master default protected
  • 553-semantic-recommendation-2
  • dev protected
  • 553-semantic-recommendation
  • replication_test
  • release-1.10 protected
  • release-1.9 protected
  • 551-init-broker-service-permissions
  • 549-test-oai-pmh
  • 545-saving-multiple-times-breaks-pid-metadata
  • 499-standalone-compute-service-2
  • 539-load-tests
  • hotfix/helm-chart
  • luca_ba_new_interface
  • 534-bug-when-adding-access-to-user-that-is-not-registered-at-dashboard-service
  • release-1.8 protected
  • 533-integrate-semantic-recommendation
  • feature/openshift
  • 518-spark-doesn-t-map-the-headers-correct
  • 485-fixity-checks
  • v1.10.3 protected
  • v1.10.2 protected
  • v1.10.1 protected
  • v1.10.0-rc13 protected
  • v1.10.0-rc12 protected
  • v1.10.0-rc11 protected
  • v1.10.0-rc10 protected
  • v1.10.0-rc9 protected
  • v1.10.0-rc8 protected
  • v1.10.0-rc7 protected
  • v1.10.0-rc6 protected
  • v1.10.0-rc5 protected
  • v1.10.0-rc4 protected
  • v1.10.0-rc3 protected
  • v1.10.0-rc2 protected
  • v1.10.0rc1 protected
  • v1.10.0rc0 protected
  • v1.10.0 protected
  • v1.9.3 protected
  • v1.9.2 protected
41 results

README.md

Blame
  • Martin Weise's avatar
    cc9a3138
    History

    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

    Future

    • Searching

    Contact