DataYoga for Python
Project description
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.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:
import datayoga_core as dy
from datayoga_core.job import Job
from datayoga_core.utils import read_yaml
job_settings = read_yaml("example.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"}) == {"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:
fname
field renamed tofirst_name
.lname
field renamed tolast_name
.country
field added based on an SQL expression.full_name
field added based on a JMESPath expression.greeting
field added based on an SQL expression.
Examples
-
Add a new field
country
out of an SQL expression that concatenatescountry_code
andcountry_name
fields after upper case the later:uses: add_field with: field: country language: sql expression: country_code || ' - ' || UPPER(country_name)
-
Rename
fname
field tofirst_name
andlname
field tolast_name
:uses: rename_field with: fields: - from_field: fname to_field: first_name - from_field: lname to_field: last_name
-
Remove
credit_card
field: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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file datayoga_core-1.48.0.tar.gz
.
File metadata
- Download URL: datayoga_core-1.48.0.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58b0a593d630334ffab126b44a448e623e1621d8139134fe357dfd3722c2d0cd |
|
MD5 | de61b1641d36b566baaf0a0367664c44 |
|
BLAKE2b-256 | 5a5bcc778415589f3de99b772d7177170b64c61a7c0a47a90f8750d75a4c6b45 |
File details
Details for the file datayoga_core-1.48.0-py3-none-any.whl
.
File metadata
- Download URL: datayoga_core-1.48.0-py3-none-any.whl
- Upload date:
- Size: 49.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fafc563e26e4b5164a97c2bb309d378f9ef58e5a7bc02e12e89204ebe97d7afc |
|
MD5 | f1922f0b477ede24cd619774ce87eb17 |
|
BLAKE2b-256 | 57e726e5b04d2c4d727346f1efe517a0c8a301e0dce8955632d705cea4e78f4d |