Skip to main content

KickbackCalculator by packr.build

A tiny Python CLI and library for turning semicolon CSV rows into grouped kickback totals.

Table of Contents

Why this package

KickbackCalculator is a minimal Python package for a very specific job: take semicolon-separated CSV input, group rows by currency, customer, and kickback percent, then emit a clean CSV report with per-group kickbacks and per-currency totals.

It is designed as both a reusable library and a command-line tool. That means you can call calculate_kickbacks(csv_text) directly in tests or scripts, or run the kickback-calculator command against files from your shell.

The implementation stays intentionally small and standard-library only. There is no web framework, no database, no external CSV dependency, and no runtime package beyond Python itself.

Features

  • Library API: kickbackcalculator.calculate_kickbacks(csv_text: str) -> str
  • CLI command: kickback-calculator input.csv -o output.csv
  • Stdout fallback when -o/--output is omitted
  • UTF-8 input and output by default, with --encoding support
  • Semicolon-delimited CSV parsing via the Python standard library
  • Skips the first row as a header
  • Ignores blank rows and rows with fewer than 11 columns
  • Uses fixed PHP-compatible columns: customer=2, currency=8, amount=9, kickback percent=10
  • Uses decimal.Decimal internally for money-like calculations
  • Emits per-currency TOTAL rows
  • Formats output with two decimals, decimal comma, and space thousands separators
  • Deterministic output ordering

Requirements

  • Python >=3.11 (Python 3.11 and 3.12 supported)
  • Standard library only at runtime
  • pytest ^8.0 for development and testing
  • No framework required

Installation

KickbackCalculator is published to PyPI as jake142-kickbackcalculator.

Install from PyPI

uv pip install jake142-kickbackcalculator

Development

If you cloned the repository, install the project and its dev dependencies with:

uv sync

Configuration

KickbackCalculator does not use environment variables or config keys.

  • Environment variables: none
  • Config keys: none

Quick start

Create a small input file and run the CLI:

cat > input.csv <<'CSV'
col0;col1;col2;col3;col4;col5;col6;col7;col8;col9;col10
x;y;Customer A;z;z;z;z;z;SEK;1000,00;10
x;y;Customer A;z;z;z;z;z;SEK;500,00;10
CSV

kickback-calculator input.csv -o output.csv
cat output.csv

Expected output:

customer;kickback;currency
Customer A;150,00;SEK
TOTAL;150,00;SEK

Usage

Python API

Use the public function when you want to convert CSV text in memory:

from kickbackcalculator import calculate_kickbacks

csv_text = """col0;col1;col2;col3;col4;col5;col6;col7;col8;col9;col10
x;y;Customer A;z;z;z;z;z;SEK;1000,00;10
x;y;Customer A;z;z;z;z;z;SEK;500,00;10
"""

result = calculate_kickbacks(csv_text)
print(result)

CLI

Convert a file and write the result to another file:

kickback-calculator input.csv -o output.csv

Write to stdout instead:

kickback-calculator input.csv

Read and write using a different encoding if needed:

kickback-calculator input.csv -o output.csv --encoding latin-1

Input and output rules

Input format

  • Delimiter: semicolon (;)
  • The first row is always treated as a header and skipped
  • Blank rows are ignored
  • Rows with fewer than 11 columns are ignored
  • Fixed zero-based columns:
    • customer: column 2
    • currency: column 8
    • amount: column 9
    • kickback percent: column 10

Parsing rules

  • Amount and kickback percent values are trimmed before parsing
  • Decimal commas are normalized to decimal points before conversion
  • Malformed numeric rows are skipped by default
  • The library does not print warnings
  • The CLI reports user/input errors concisely on stderr

Grouping and totals

Rows are grouped by:

  1. currency
  2. customer
  3. kickback percent

For each group, kickback is calculated as:

summed amount * percent / 100

The output then appends one TOTAL row per currency.

Output format

  • Header: customer;kickback;currency
  • Rows: {customer};{formatted_kickback};{currency}
  • Totals: TOTAL;{formatted_total};{currency}
  • Numbers use exactly two decimals
  • Decimal comma is used in output
  • A space is used as the thousands separator
  • Output ends with a trailing newline

Example formatting:

  • 1234.5 -> 1 234,50
  • 10 -> 10,00

Testing

Run the test suite with uv:

uv run pytest

The tests cover the public library API and the CLI behavior, including file output and stdout fallback. No external services are called.

Project layout

The package uses a small src/ layout:

pyproject.toml
README.md
src/kickbackcalculator/__init__.py
src/kickbackcalculator/core.py
src/kickbackcalculator/cli.py
tests/test_core.py
tests/test_cli.py

The public import path is kickbackcalculator, and the console script is kickback-calculator.

Metadata

Release files for jake142-kickbackcalculator 0.1.1

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

Source distribution (sdist)

Source distribution for jake142-kickbackcalculator 0.1.1
File Size Uploaded Provenance Actions
jake142_kickbackcalculator-0.1.1.tar.gz 7.3 kB Without provenance Details for jake142_kickbackcalculator-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jake142-kickbackcalculator 0.1.1
File Interpreter ABI Platform Actions
jake142_kickbackcalculator-0.1.1-py3-none-any.whl Python 3 none any Details for jake142_kickbackcalculator-0.1.1-py3-none-any.whl

Total release size: 14.9 kB

Release files / jake142_kickbackcalculator-0.1.1.tar.gz

Download URL jake142_kickbackcalculator-0.1.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d09952404804244b40b101c03818fb406d2614429954f533351e9bcb9b92b29c
BLAKE2b-256 checksum
How to use checksums
14ea62d3bd46f28421c4cef9621e319b19633927f32ec4fa7efdfd39e1ab80c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / jake142_kickbackcalculator-0.1.1-py3-none-any.whl

Download URL jake142_kickbackcalculator-0.1.1-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7932e70790447723784ca6cde2c4d2835c12933e1f5d9db10b41eec305b812b2
BLAKE2b-256 checksum
How to use checksums
e219fad506128bb6e5d7628964b6482ab9c67968d998346d0b939e4b1941af68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for jake142-kickbackcalculator 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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