Skip to main content

A collection of extensions for PETL

Project description

petl_addons

This is a library that adds

Installation

pip install petl_addons

Usage

import petl_addons

apply

This patches the petl Table class with an apply method calls the specified function with the table. This allows pipeline fragments to be defined and applied in a clear format.

def filter_values(table):
    return table.selecteq('value', 10).selectnotnone('name')

table.apply(filter_values)

args and kwargs are passed through to the function:

def op(table, field, inflation=10):
    return table.convert(field, lambda f: f+inflation)

table.apply(op, 'value', inflation=20) // Will inflate the value field by 20

Multiple separate fragments can be chained together, greatly enhancing code readability and reusability.

table.apply(filter_values).apply(summarise_data).apply(write_csv)

The module also overloads the | character to allow the following usage, equivalent to the example above:

table | filter_values | summarise_data | write_csv

NB this won't work with parameter functions.

If you wish to load this on its own without any other modules, use the statement below.

import petl_addons.apply

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

petl_addons-0.0.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

petl_addons-0.0.1-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file petl_addons-0.0.1.tar.gz.

File metadata

  • Download URL: petl_addons-0.0.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for petl_addons-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a4a79cfb061a78f2378b058a52e7d7751e4a4af1de970b71d4c3416b0d9c18f2
MD5 c42e12b2bdfaa8adbdb5efceb6aab6ea
BLAKE2b-256 eeaada7b08af6a8d602d453d405b797831127779fdef678c9511c60b6996267d

See more details on using hashes here.

File details

Details for the file petl_addons-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: petl_addons-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.4

File hashes

Hashes for petl_addons-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a34b46894f838217cd7d8f58f124e357fcb4cb00d28c9f2bc3e460f9cd39cee7
MD5 1dfd12f710c27b74212706e00ff4f434
BLAKE2b-256 77ab3918fcec2db78a7c2f799f28c2a08f2efa30cd484e3ca068d9d0b571d4f4

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