Skip to main content

Databrary API wrapper

Project description

Python Databrary API Wrapper

This is a Python wrapper around databrary API

Installation

Run the following to install:

pip install pydatabrary

Usage

Databrary API

from pybrary import Pybrary

# Start a Databrary session
pb = Pybrary.get_instance('USERNAME', 'PASSWORD')
# You need to have permissions to the volume, to interact with it
volume_info = pb.get_volume_info(1)
print(volume_info)

Databrary Curation

Generate templates

This will generate for you template files where you can curate your new volume

from pybrary import Curation

# The number of records that you need for your ingest
payload = {
    'participant': 0,
    'pilot': 0,
    'exclusion': 0,
    'condition': 0,
    'group': 0,
    'task': 0,
    'context': 0,
}
records = Curation.generate_records(categories=payload, output='/PATH/TO/OUTPUT/CSV')

# Generate an asset csv file from a local folder
assets = Curation.generate_assets('PATH/TO/FOLDER/', output='/PATH/TO/OUTPUT/CSV')

# Value is the number of containers you wish to generate
containers = Curation.generate_containers(value=2, output='/PATH/TO/OUTPUT/CSV')

Read CSV files

After you edit your CSV files you will have to pass them to Curation to validate them and generate the JSON file needed for your ingest

Only the containers file is required. if you provide assets and records files,Curation will populate asset and record ids found in the container from the provided files.

Note: pybrary will ignore duplicate keys, so make sure to have unique ids for your rows

from pybrary import Curation

volume = Curation.from_files(
    volume_name="TEST", 
    containers_file='PATH/TO/CONTAINER/FILE',
    assets_file='PATH/TO/ASSET/FILE',
    records_file='PATH/TO/RECORD/FILE'
)

Generate the ingest file

from pybrary import Curation

volume = Curation.from_files(
    volume_name="TEST", 
    containers_file='PATH/TO/CONTAINER/FILE',
    assets_file='PATH/TO/ASSET/FILE',
    records_file='PATH/TO/RECORD/FILE'
)
Curation.to_json(volume, '/PATH/TO/JSON/OUTPUT')

Duplicate existing volume

Get your volume from databrary

from pybrary import Curation

volume = Curation.from_databrary(
    volume_id=1,
    username='YOUR_USERNAME',
    password='YOUR_PASSWORD'
)

# You can edit your volume programmatically or dump your volume in
# csv files that you can edit with your text editor
Curation.to_files(
    volume, 
    containers_output='PATH/TO/CONTAINER/FILE',
    assets_output='PATH/TO/ASSET/FILE',
    records_output='PATH/TO/RECORD/FILE'
)
# once your are done you can import your files

Generate the SQL query to execute on the server (Please contact Databray admin)

from pybrary import Curation
# Source is the source volume
# Target is the target volume
Curation.generate_sql_query(volume_id=1)

The SQL query will create a script in /tmp/volume_id.sh that need to be executed prior to the ingest, it will copy the volume's asset into a staging folder.

Note: The staging folder on the server (where files are copied) and the path of the file in the final ingest file must match

Development

Test

pytest

Install Locally

pip install -e .

Build

python -m build

Publish

twine upload dist/*

TODOs

  • Generate documentation and add examples.
  • Check for duplicate records and asset id.
  • check if the record measures are valid.
  • Fix utils methods.

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

pydatabrary-0.9.1.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

pydatabrary-0.9.1-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file pydatabrary-0.9.1.tar.gz.

File metadata

  • Download URL: pydatabrary-0.9.1.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5

File hashes

Hashes for pydatabrary-0.9.1.tar.gz
Algorithm Hash digest
SHA256 8e5c31bf431a9c682cbe8e1a1d64254ea0c624421af672c60b80deb115ce0dc2
MD5 5ed967e8f2ff6081e8da7d6574b29159
BLAKE2b-256 4febbddb50937bb019f09bbb9eb33512aa603ac660d0176ea82cead60d4c265e

See more details on using hashes here.

File details

Details for the file pydatabrary-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: pydatabrary-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.5

File hashes

Hashes for pydatabrary-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2ca791217b7ae282baaf35a667823eb73c71173b60d3403387e8a7754e742c6
MD5 e938156e79703f5ed067fa0b8e15f696
BLAKE2b-256 bbf5ded7c825300e2038d5cadcb2c4280d205c804c36b86be0dc425ea487d6dd

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