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.
Release files for pydatabrary 0.9.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydatabrary-0.9.1.tar.gz | 22.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydatabrary-0.9.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.8 kB
Release files / pydatabrary-0.9.1.tar.gz
| Download URL | pydatabrary-0.9.1.tar.gz |
|---|---|
| Size | 22.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e5c31bf431a9c682cbe8e1a1d64254ea0c624421af672c60b80deb115ce0dc2
|
|
BLAKE2b-256 checksum How to use checksums |
4febbddb50937bb019f09bbb9eb33512aa603ac660d0176ea82cead60d4c265e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / pydatabrary-0.9.1-py3-none-any.whl
| Download URL | pydatabrary-0.9.1-py3-none-any.whl |
|---|---|
| Size | 30.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2ca791217b7ae282baaf35a667823eb73c71173b60d3403387e8a7754e742c6
|
|
BLAKE2b-256 checksum How to use checksums |
bbf5ded7c825300e2038d5cadcb2c4280d205c804c36b86be0dc425ea487d6dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|