DataYoga Core
Introduction
datayoga-core is the transformation engine used in DataYoga, a framework for building and generating data pipelines.
Installation
pip install datayoga-core
Quick Start
This demonstrates how to transform data using a DataYoga job.
Create a Job
Use this example.dy.yaml:
steps:
- uses: add_field
with:
fields:
- field: full_name
language: jmespath
expression: concat([fname, ' ' , lname])
- field: country
language: sql
expression: country_code || ' - ' || UPPER(country_name)
- uses: rename_field
with:
fields:
- from_field: fname
to_field: first_name
- from_field: lname
to_field: last_name
- uses: remove_field
with:
fields:
- field: credit_card
- field: country_name
- field: country_code
- uses: map
with:
expression:
{
first_name: first_name,
last_name: last_name,
greeting: "'Hello ' || CASE WHEN gender = 'F' THEN 'Ms.' WHEN gender = 'M' THEN 'Mr.' ELSE 'N/A' END || ' ' || full_name",
country: country,
full_name: full_name
}
language: sql
Transform Data Using datayoga-core
Use this code snippet to transform a data record using the job defined above. The transform method returns a tuple of processed, filtered, and rejected records:
import datayoga_core as dy
from datayoga_core.job import Job
from datayoga_core.result import Result, Status
from datayoga_core.utils import read_yaml
job_settings = read_yaml("example.dy.yaml")
job = dy.compile(job_settings)
assert job.transform([{"fname": "jane", "lname": "smith", "country_code": 1, "country_name": "usa", "credit_card": "1234-5678-0000-9999", "gender": "F"}]).processed == [
Result(status=Status.SUCCESS, payload={"first_name": "jane", "last_name": "smith", "country": "1 - USA", "full_name": "jane smith", "greeting": "Hello Ms. jane smith"})]
The job can also be provided as a parsed json inline:
import datayoga_core as dy
from datayoga_core.job import Job
from datayoga_core.result import Result, Status
import yaml
import textwrap
job_settings = textwrap.dedent("""
steps:
- uses: add_field
with:
fields:
- field: full_name
language: jmespath
expression: concat([fname, ' ' , lname])
- field: country
language: sql
expression: country_code || ' - ' || UPPER(country_name)
- uses: rename_field
with:
fields:
- from_field: fname
to_field: first_name
- from_field: lname
to_field: last_name
- uses: remove_field
with:
fields:
- field: credit_card
- field: country_name
- field: country_code
- uses: map
with:
expression:
{
first_name: first_name,
last_name: last_name,
greeting: "'Hello ' || CASE WHEN gender = 'F' THEN 'Ms.' WHEN gender = 'M' THEN 'Mr.' ELSE 'N/A' END || ' ' || full_name",
country: country,
full_name: full_name
}
language: sql
""")
job = dy.compile(yaml.safe_load(job_settings))
assert job.transform([{"fname": "jane", "lname": "smith", "country_code": 1, "country_name": "usa", "credit_card": "1234-5678-0000-9999", "gender": "F"}]).processed == [
Result(status=Status.SUCCESS, payload={"first_name": "jane", "last_name": "smith", "country": "1 - USA", "full_name": "jane smith", "greeting": "Hello Ms. jane smith"})]
As can be seen, the record has been transformed based on the job:
fnamefield renamed tofirst_name.lnamefield renamed tolast_name.countryfield added based on an SQL expression.full_namefield added based on a JMESPath expression.greetingfield added based on an SQL expression.
Examples
-
Add a new field
countryout of an SQL expression that concatenatescountry_codeandcountry_namefields after upper case the later:uses: add_field with: field: country language: sql expression: country_code || ' - ' || UPPER(country_name)
-
Rename
fnamefield tofirst_nameandlnamefield tolast_name:uses: rename_field with: fields: - from_field: fname to_field: first_name - from_field: lname to_field: last_name
-
Remove
credit_cardfield:uses: remove_field with: field: credit_card
For a full list of supported block types see reference.
Expression Language
DataYoga supports both SQL and JMESPath expressions. JMESPath are especially useful to handle nested JSON data, while SQL is more suited to flat row-like structures.
For more information about custom functions and supported expression language syntax see reference.
Metadata
Release files for datayoga-core 1.137.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 |
|---|---|---|---|---|
| datayoga_core-1.137.0.tar.gz | 66.1 kB | Without provenance | Details for datayoga_core-1.137.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datayoga_core-1.137.0-py3-none-any.whl | Python 3 | none | any | Details for datayoga_core-1.137.0-py3-none-any.whl |
Total release size: 172.6 kB
Release files / datayoga_core-1.137.0.tar.gz
| Download URL | datayoga_core-1.137.0.tar.gz |
|---|---|
| Size | 66.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6e7d2c74e57d649715a03144409b84298f640bb297112ea466c40df09c45ce5
|
|
BLAKE2b-256 checksum How to use checksums |
bbeb3350ba5523bebcbba79c2905dff6727f00cdb5fe48db60b45d523b9662c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / datayoga_core-1.137.0-py3-none-any.whl
| Download URL | datayoga_core-1.137.0-py3-none-any.whl |
|---|---|
| Size | 106.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a7c7c4ac74bbe7bd1ce87246641c3252df79362db3d3b39c7cc9ffda5edbf02
|
|
BLAKE2b-256 checksum How to use checksums |
21f3e390d715c9e10fa42e66663b6d6e7485f24cc739e1b5462abbd845285625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for datayoga-core 1.137.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.