yw_core
Core elements of YesWorkflow in Python.
Installation
git clone <url>
cd yw_core
pip install .
An example using a Python notebook with 3 code cells
Here is the example Python notebook that will be used as the running example to explain the CLI and Python API.
# cell 1
x = 1
# cell 2
func(x)
# cell 3
x
CLI
Usage: yw [OPTIONS]
Options:
-f, --filepath TEXT Path of a Python notebook to extract YesWorkflow
annotations [required]
-u, --upper Extract upper estimate of cell I/O sets for YesWorkflow
annotations
--help Show this message and exit.
Lower estimate
yw -f YOUR_PYTHON_NOTEBOOK_PATH
Expected output for lower estimate:
# @BEGIN cell-1
# @OUT x
# @END cell-1
# @BEGIN cell-2
# @IN x
# @END cell-2
# @BEGIN cell-3
# @IN x
# @END cell-3
Upper estimate
yw -f YOUR_PYTHON_NOTEBOOK_PATH -u
Expected output for upper estimate:
# @BEGIN cell-1
# @OUT x
# @END cell-1
# @BEGIN cell-2
# @IN x
# @OUT x @AS x-1
# @END cell-2
# @BEGIN cell-3
# @IN x @AS x-1
# @END cell-3
Python API
Lower estimate
from yw_core.yw_core import extract_code_cells, extract_records, records2annotations
code_cells = extract_code_cells("YOUR_PYTHON_NOTEBOOK_PATH")
records = extract_records(code_cells, is_upper_estimate=False)
annotations = records2annotations(records)
Expected outputs for lower estimate:
code_cells = ['x = 1', 'func(x)', 'x']
records = [
{'inputs': set(), 'output_candidates': {'x'}, 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': {'x'}},
{'inputs': {'x'}, 'output_candidates': set(), 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': set()},
{'inputs': {'x'}, 'output_candidates': set(), 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': set()}
]
annotations = '# @BEGIN cell-1\n# @OUT x\n# @END cell-1\n\n# @BEGIN cell-2\n# @IN x\n# @END cell-2\n\n# @BEGIN cell-3\n# @IN x\n# @END cell-3'
Upper estimate
from yw_core.yw_core import extract_code_cells, extract_records, records2annotations
code_cells = extract_code_cells("YOUR_PYTHON_NOTEBOOK_PATH")
records = extract_records(code_cells, is_upper_estimate=True)
annotations = records2annotations(records)
Expected outputs for upper estimate:
code_cells = ['x = 1', 'func(x)', 'x']
records = [
{'inputs': set(), 'output_candidates': {'x'}, 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': {'x'}},
{'inputs': {'x'}, 'output_candidates': {'x'}, 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': {'x-1'}},
{'inputs': {'x-1'}, 'output_candidates': set(), 'refers_code': set(), 'defines_code': set(), 'alias_stmt': None, 'alias_vars': set(), 'outputs': set()}
]
annotations = '# @BEGIN cell-1\n# @OUT x\n# @END cell-1\n\n# @BEGIN cell-2\n# @IN x\n# @OUT x @AS x-1\n# @END cell-2\n\n# @BEGIN cell-3\n# @IN x @AS x-1\n# @END cell-3'
Tests
We use tox to run Python unit test (pytest):
# If you the tox package is not installed
pip install tox
# Run unit test
tox
Metadata
Release files for yw-core 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yw_core-0.1.0.tar.gz | 12.4 kB | Without provenance | Details for yw_core-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yw_core-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for yw_core-0.1.0-py3-none-any.whl |
Total release size: 21.7 kB
Release files / yw_core-0.1.0.tar.gz
| Download URL | yw_core-0.1.0.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10e72bcb8ab56a8644ff9275a1a8ed421cf04eb9b9dec2e21723ac3097d8ae4b
|
|
BLAKE2b-256 checksum How to use checksums |
32978ee49e06afcc4b3bd16bbda3f4cebb4fbdf13f5bdf50028fc9fc7588d509
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.1
|
Release files / yw_core-0.1.0-py3-none-any.whl
| Download URL | yw_core-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab2519c130006d51aa53c34630570355ebb4a6b8044ec6588d4ff69fc081cbbd
|
|
BLAKE2b-256 checksum How to use checksums |
3583e837426ff470a7e8512a201cb8c13a8649e23cf5d249f7a9c49d45660b5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.1
|
Security for yw-core 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.