JSON Schema for FireWorks
JSON Schema for FireWorks
Why should I use JSON schema?
The input for FireWorks is often provided in JSON or YAML formats and generated by third-party software that is unaware of the valid data types in FireWorks. Latent mismatches of data types may produce run-time errors, such as missing keywords or wrong data types, that are more difficult to handle than a validation of the initial input.
The fireworks_schema package provides a formal human- and machine-readable description of the data types used in classes in FireWorks. Additionally, a function is provided that checks the validity of JSON and YAML inputs immediately before deserialization.
The recommended way to install this package into your virtual environment is using
pip (in any folder):
python -m pip install fireworks-schema
Alternatively you can download a release from the GitHub
repository, unpack the archive, change into the folder containing
setup.py and run:
python setup.py install
After the installation you can run the tests, for example using the nose package:
Using fireworks_schema to validate input for FireWorks
There are two ways to perform JSON schema validation:
- Call the schema validator explicitly
- Activate automatic schema validation
Call the schema validator explicitly
This is the case when you use Python but read JSON/YAML serialized objects provided externally. In the following example, a serialized workflow object is loaded from a YAML file and validated against the Workflow schema:
import yaml import fireworks_schema from fireworks import Workflow with open('empty_fws.yaml', 'rt') as yf: dct = yaml.safe_load(yf) fireworks_schema.validate(dct, 'Workflow') wf = Workflow.from_dict(dct)
Activate automatic schema validation
To activate automatic schema validation you must specify:
in your FWConfig file. For more details about managing your FWConfig file see the FW Config tutorial.
The default value of
If automatic validation is turned on, i.e.
then validation is performed only for the classes specified in the list
JSON_SCHEMA_VALIDATE_LIST, whenever an object of these
classes is loaded from file. There is no default for
and therefore you must set
JSON_SCHEMA_VALIDATE_LIST in your FWConfig file.
For example, to turn on automatic validation for serialized
Workflow objects these two lines must be added to the FWConfig file:
JSON_SCHEMA_VALIDATE: true JSON_SCHEMA_VALIDATE_LIST: [Firework, Workflow]
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size fireworks_schema-1.0.1-py3-none-any.whl (66.0 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size fireworks_schema-1.0.1.tar.gz (27.9 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for fireworks_schema-1.0.1-py3-none-any.whl