Skip to main content

dictionaryutils

python wrapper and metaschema for datadictionary. It can be used to:

  • load a local dictionary to a python object.
  • dump schemas to a file that can be uploaded to s3 as an artifact.
  • load schema file from an url to a python object that can be used by services

Test for dictionary validity with Docker

Say you have a dictionary you are building locally and you want to see if it will pass the tests.

You can add a simple alias to your .bash_profile to enable a quick test command:

testdict() { docker run --rm -v $(pwd):/dictionary quay.io/cdis/dictionaryutils:master; }

Then from the directory containing the gdcdictionary directory run testdict.

Generate simulated data with Docker

If you wish to generate fake simulated data you can also do that with dictionaryutils and the data-simulator.

simdata() { docker run --rm -v $(pwd):/dictionary -v $(pwd)/simdata:/simdata quay.io/cdis/dictionaryutils:master; /bin/bash -c "cd /dictionary/dictionaryutils; bash dockerrun.bash; cd /dictionary/dictionaryutils; poetry run python bin/simulate_data.py --path /dictionary/simdata $*; export SUCCESS=$?; cd /dictionary; rm -rf build dictionaryutils dist gdcdictionary.egg-info; chmod -R a+rwX /simdata; exit $SUCCESS "; }

Then from the directory containing the gdcdictionary directory run simdata and a folder will be created called simdata with the results of the simulator run. You can also pass in additional arguments to the data-simulator script such as simdata --max_samples 10.

The --max_samples argument will define a default number of nodes to simulate, but you can override it using the --node_num_instances_file argument. For example, if you create the following instances.json:

{
        "case": 100,
        "demographic": 100
}

Then run the following:

docker run --rm -v $(pwd):/dictionary -v $(pwd)/simdata:/simdata quay.io/cdis/dictionaryutils:master /bin/bash -c "cd /dictionaryutils; bash dockerrun.bash; cd /dictionary/dictionaryutils; poetry run python bin/simulate_data.py --path /simdata/ --program workshop --project project1 --max_samples 10 --node_num_instances_file /dictionary/instances.json; export SUCCESS=$?; rm -rf build dictionaryutils dist gdcdictionary.egg-info; chmod -R a+rwX /simdata; exit $SUCCESS";

Then you'll get 100 each of case and demographic nodes and 10 each of everything else. Note that the above example also defines program and project names.

You can also run the simulator for an arbitrary json url with the --url parameter. The alias can be simplified to skip the set up of the parent directory virtual env (ie, skip the docker_run.bash):

simdataurl() { docker run --rm -v $(pwd):/dictionary -v $(pwd)/simdata:/simdata quay.io/cdis/dictionaryutils:master /bin/bash -c "python /dictionaryutils/bin/simulate_data.py simulate --path /simdata/ $*; chmod -R a+rwX /simdata"; }

Then run simdataurl --url https://datacommons.example.com/schema.json.

Using a local build of the Docker image

It is possible to use a local build of the dictionaryutils Docker image instead of the master branch stored in quay.

From a local copy of the dictionaryutils repo, build and tag a Docker image, for example

docker build -t dictionaryutils-mytag .

Then use this image in any of the aliases and commands mentioned above by replacing quay.io/cdis/dictionaryutils:master with dictionaryutils-mytag.

Use dictionaryutils to load a dictionary

from dictionaryutils import DataDictionary

dict_fetch_from_remote = DataDictionary(url=URL_FOR_THE_JSON)

dict_loaded_locally = DataDictionary(root_dir=PATH_TO_SCHEMA_DIR)

Use dictionaryutils to dump a dictionary

import json
from dictionaryutils import dump_schemas_from_dir

with open('dump.json', 'w') as f:
    json.dump(dump_schemas_from_dir('../datadictionary/gdcdictionary/schemas/'), f)

Metadata

Release files for dictionaryutils 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dictionaryutils 4.0.0
File Size Uploaded
dictionaryutils-4.0.0.tar.gz 14.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dictionaryutils 4.0.0
File Interpreter ABI Platform
dictionaryutils-4.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.2 kB

Release files / dictionaryutils-4.0.0.tar.gz

Download URL dictionaryutils-4.0.0.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c846c48d534c7ae4a47d65b29cb7bb4324e998366e81ff5cc2175c94b1ea0c77
BLAKE2b-256 checksum
How to use checksums
929f721aa12d8730d09eaac9589f2f900f04ab9b83ee6a07fc0a5c831fc26241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure

Release files / dictionaryutils-4.0.0-py3-none-any.whl

Download URL dictionaryutils-4.0.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6d1b2af957ffd2c66df42a1398fee1bd30b0268df82d9630236ed23286500a0
BLAKE2b-256 checksum
How to use checksums
33aa25563d55b055708c92b49a495f73cc3fc00529525cee77d7dc8e50e83265
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.11 Linux/6.11.0-1018-azure

Release history Release notifications | RSS feed

This release

4.0.0 This release

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.11

1 release file

3.4.10

1 release file

3.4.9

1 release file

3.4.8

1 release file

3.4.6

1 release file

3.4.5

1 release file

3.4.4

1 release file

3.4.3

1 release file

3.4.2

1 release file

3.4.1

1 release file

3.4.0

1 release file

3.3.0

1 release file

3.2.0

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

1 release file

2.0.4

1 release file

2.0.3

1 release file

2.0.2

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.2.2

1 release file

1.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page