Skip to content
Snippets Groups Projects
Select Git revision
  • 293c338ed0eabf5a0b8812d901f35611f569bca1
  • master default protected
  • replication_test
  • release-1.10 protected
  • dev protected
  • 556-usage-statistics
  • 553-semantic-recommendation-2
  • 553-semantic-recommendation
  • 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
  • v1.10.4 protected
  • 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
41 results

python.md

Blame
  • Martin Weise's avatar
    Martin Weise authored
    293c338e
    History
    author: Martin Weise

    PyPI - Version{ tabindex=-1 }

    tl;dr

    :fontawesome-solid-cube:  View Docs{ .md-button .md-button--primary tabindex=-1 }

    Installing

    :octicons-tag-16:{ title="Minimum version" } 1.4.2

    $ python -m pip install dbrepo

    To use DBRepo in your Jupyter notebook, install the dbrepo library` directly in a code cell and type:

    !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.")

    The library is well-documented, please see the full documentation or the PyPI page.

    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

    Secrets

    It is not recommended to store credentials directly in the notebook as they will be versioned with git, etc. Use environment variables instead:

    DBREPO_ENDPOINT=https://test.dbrepo.tuwien.ac.at
    DBREPO_USERNAME=foo
    DBREPO_PASSWORD=bar
    DBREPO_SECURE=True

    Then use the default constructor of the RestClient to e.g. analyse a CSV. Your secrets are automatically passed:

    from dbrepo.RestClient import RestClient
    
    client = RestClient()
    analysis = client.analyse_datatypes(file_path="sensor.csv", separator=",")

    Future

    • Searching

    Links

    This information is also mirrored on PyPI.