Skip to main content

A Python package for using Polars from configuration

Project description

Polars as Config

This library allows you to define Polars operations using a configuration format (JSON or Python dict), making it easy to serialize, store, and share data processing pipelines.

For a high-level overview, mission, vision, and a list of features, please see the [[Home|Home]] page of our Wiki. For detailed technical explanations and examples of all features, please visit the [[Technical Features|Technical-Features]] page on our Wiki.

Quick Start

from polars_as_config.config import run_config

# Define your operations in a config
config = {
    "steps": [
        # Read a CSV file
        {"operation": "scan_csv", "kwargs": {"source": "data.csv"}},

        # Add a new column by joining two string columns
        {
            "operation": "with_columns",
            "kwargs": {
                "full_name": {
                    "expr": "str.concat",
                    "on": {"expr": "col", "kwargs": {"name": "first_name"}},
                    "kwargs": {
                        "delimiter": " ",
                        "other": {"expr": "col", "kwargs": {"name": "last_name"}}
                    }
                }
            }
        }
    ]
}

# Run the config
result = run_config(config)

Config Format Overview

The configuration is a JSON object (or Python dictionary) that describes a series of data processing steps. Each step in the "steps" array typically includes:

  • "operation": The Polars operation to perform (e.g., "scan_csv", "with_columns", "filter").
  • "args": A list of positional arguments for the operation.
  • "kwargs": A dictionary of keyword arguments for the operation.

Complex operations and transformations within steps are defined using an expression format.

For a comprehensive guide on the config and expression formats, including various examples like basic operations, string operations, date operations, and advanced features like using variables and custom functions, please see our [[Technical Features|Technical-Features]] Wiki page.

Expression Format Overview

Expressions allow you to define how data should be manipulated. Key components of an expression are:

  • "expr": The name of the Polars expression function (e.g., "str.concat", "eq", "gt").
  • "on": The column or expression to apply this expression to (acting like self in an object-oriented context).
  • "args" and "kwargs": Positional and keyword arguments for the expression function.

Example: pl.col("x").gt(5)

{
  "expr": "gt",
  "on": { "expr": "col", "kwargs": { "name": "x" } },
  "kwargs": { "other": 5 }
}

For more detailed examples and explanations of how to build simple and nested expressions, refer to the [[Technical Features|Technical-Features]] page on our Wiki.

Installation

pip install polars-as-config

Requirements

  • Polars

License

See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polars_as_config-1.0.6.tar.gz (37.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polars_as_config-1.0.6-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file polars_as_config-1.0.6.tar.gz.

File metadata

  • Download URL: polars_as_config-1.0.6.tar.gz
  • Upload date:
  • Size: 37.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for polars_as_config-1.0.6.tar.gz
Algorithm Hash digest
SHA256 d7ceec10023d7c9a23bc4bb984d9df8c55447a57b651883e934b93c9ca8aab3c
MD5 00cdbad0113308e6f3240d8a51ebd579
BLAKE2b-256 8c1fb8e38e91fd4f5f837d714307b98bbd447f338b8449a36dd090dbbbf7f2a5

See more details on using hashes here.

File details

Details for the file polars_as_config-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for polars_as_config-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7494a9ed22db46900b406495fdb5cbfe40c50d01ac2a5bf2e36e3fbca21ce589
MD5 aba64f4b288fdaf28fa2ffc3cdde604f
BLAKE2b-256 2089f4c85cdc71abadcfe89635a1bf5e7f142ed23c4b2bf9c4aa4a1d9ff41cdb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page