Skip to main content

pystyx

Python implementation of Styx ETL declarative TOML.

For more information about Styx, please see the definition here.

Quick Start

  1. In your Python project, mkdir maps

  2. touch functions.styx (TODD: Add init for this) and functions.py (if you want to write custom functions)

  3. In functions.styx, add an array called functions, with the names of any functions you plan on using in your mappings:

    # functions.styx
    
    functions = ["to_upper_case"]
    
  4. In functions.py implement your custom function. Ensure that your function takes the same number of arguments as your expected input_paths, or use *args. The

    # functions.py
    
    from pystyx.functions import styx_function
    
    @styx_function
    def to_upper_case(value):
       return value.upper()
    
  5. Add any of your Styx Definitions to the maps/ directory. For example,

    from_type = "erp_address"
    to_type = "Address"
    
    [fields]
    
        [fields.address1]
        input_paths = ["addr1"]
    
        [fields.address2]
        input_paths = ["addr2"]
    
        [fields.city]
        input_paths= ["city"]
    
        [fields.state]
        input_paths = ["province"]
        function = "to_upper_case"
    
        [fields.zip]
        input_paths = ["postalCode"]
    
  6. Initialize maps in your Python code:

    // blob.json
    {
       "addr1": "123 Street",
       "addr2": "Ste. 800",
       "city": "Dallas",
       "province": "tx",
       "postalCode": "75080",
    }
    
    # main.py
    import json
    import pathlib
    
    import pystyx
    
    # Ensure that your decorated functions are evaluated
    from functions import *  
    
    with pathlib.Path("blob.json").open() as json_file:
        blob = json.load(json_file)
        maps = pystyx.create_maps()  # Defaults to `/maps` and `functions.styx`
        mapper = maps.get("erp_address")  # 'from_type` from the Definition above
        mapped_obj = mapper(blob)
        print(mapped_obj)
    

    Prints:

     {
        "address1": "123 Street",
        "address2": "Ste. 800",
        "city": "Dallas",
        "state": "TX",  // Upper case now
        "zip": "75080"
     }
    

Styx Validation

pystyx.create_maps() parses (and thereby validates) the Styx files before loading them. I hope to extract this validation as a CLI tool (along with generating Styx structures).

Styx Implementation

I wanted this to be a good first example of a Styx implementation, so I believe it currently implements all features of the Styx standard. Parsing and validation I would like to extract into its own library eventually.

Feature Implemented
Structures
- JSON objects ✔️
Validation/Parsing
- Full parsing ✔️
Preprocessing
- input_paths ✔️
- output_paths ✔️
- function ✔️
- or_else ✔️
- on_throw ✔️
Fields
- field header ✔️
- input_paths ✔️
- possible_paths ✔️
- const ✔️
- from_type ✔️
- or_else ✔️
- on_throw ✔️
- many ✔️
Postprocessing
- input_paths ✔️
- output_paths ✔️
- function ✔️
- or_else ✔️
- on_throw ✔️

Metadata

Release files for pystyx 0.8.5

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

Built distribution (wheel)

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

Release files / pystyx-0.8.5-py3-none-any.whl

Download URL pystyx-0.8.5-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b190e4bebc1edb8bcf0311f0d2c00c2074046644adc86e76bef0d5c4fd18e969
BLAKE2b-256 checksum
How to use checksums
a23e9dd322b623a57c12afed614bc48e9a1b25d9cc6f0b534cc340fa7c8b8b24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.8.5 This release

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.4

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.3

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