Skip to main content

kochen

Primarily a library of personal scripts and handy boilerplate, for scientific environments.

This library is additionally designed for strong backward-compatibility: old scripts dependent on functionality in older library versions can still run, simply by performing a soft version pin in the script (whereas, traditionally, older versions of the library itself needs to be installed).

Licensed under LGPLv2.1-or-later, because free software is best left open.

Installation

Requires Python 3.8+ (versions below 3.8 often fail with modern tooling as of 2025).

pip install kochen

The base installation has very minimal dependencies. To use certain submodules that introduce additional dependencies, specify them as an extra:

  • datautil: For data storage and parsing.
  • fitutil: For curve fitting.
  • mathutil: For general math manipulation.
  • plotutil: For plotting.
pip install kochen[datautil,fitutil]

Or just install them all:

pip install kochen[all]

Versioning

This library implements soft-versioning by means of version pinning in the script itself (how cool is that!). This prints 'latest' without version pinning:

import kochen.sampleutil
print(kochen.sampleutil.foo())

and prints 'v0.2025.8' with version pinning, all without downgrading the library:

import kochen.sampleutil  # v0.2025.8
print(kochen.sampleutil.foo())

Usage

Most of the useful functionality is parked in the following submodules: datautil, mathutil, ipcutil, scriptutil.

import kochen.mathutil
kochen.mathutil.generate_simplex(...)

Some commonly used features are listed below.

ipcutil

Client/Server for proxying Python instances over TCP ports.

# server.py
from kochen.ipcutil import Server
from S15lib.instruments.powermeter import Powermeter

pm = Powermeter(...)
pm = Server(pm, address="192.168.1.2", port=3000)
pm.run()

# client.py
from kochen.ipcutil import Client
from S15lib.instruments.powermeter import Powermeter

pm = Client(Powermeter, address="192.168.1.2", port=3000)
print(pm.voltage)

datautil

Data logging and reconstruction:

from kochen.datautil import pprint

filename = "pv_curve.log"
pprint("volt_V", "power_W", "comment", out=filename)
pprint(1, 3, "first_line", out=filename)
pprint(1.5, 9, "second_line", out=filename)
#  volt_V power_W comment
#       1       3 first_line
#     1.5       9 second_line

print(load(filename, schema=[float, float, str]))
# shape: (2, 3)
# ┌────────┬─────────┬─────────────┐
# │ volt_V ┆ power_W ┆ comment     │
# │ ---    ┆ ---     ┆ ---         │
# │ f64    ┆ f64     ┆ str         │
# ╞════════╪═════════╪═════════════╡
# │ 1.0    ┆ 3.0     ┆ first_line  │
# │ 1.5    ┆ 9.0     ┆ second_line │
# └────────┴─────────┴─────────────┘

Data aggregation:

from kochen.datautil import Collector

c = Collector()
c.indices, c.signals = (1, 2)
c.indices, c.signals = (3, 4)
c.indices, c.signals = (6, 7)

print(c.indices)  # [1, 3, 6]

Cache backed by file:

import time
from kochen.datautil import filecache

@filecache(path="mycache", backend="json")
def initialize(duration):
    time.sleep(duration)
    return duration

print(initialize(1))  # 1 (sleeps for 1s)
print(initialize(1))  # 1 (no sleep)

with open("mycache") as f:
    print(f.read())  # {"initialize": {"((1,), frozenset())": 1}}

template

Initialize a quick script boilerplate at MYSCRIPT.py:

python -m kochen.template MYSCRIPT

Others

Strong backward-compatibility?

Maybe not as strong as its proper definition implies (since it depends on the user properly deprecating functions in the first place), but it mostly does the job as advertised.

Unlike typical software engineering where application or library packages are created, one-off scripting is very common in scientific environments, since lots of prototyping and data exploration is performed. A common practice includes installing the latest library in the system Python (or more sanely, in a global virtual environment / conda), then using it to develop scripts. Superseding of old functions meant old scripts tend to fail to run, and hence the subsequent hesitation to upgrade the library/Python.

Allowing soft version pinning of the library should ideally fix this issue. See the versioning writeup to see how this is implemented, and the old design document for the initial conception and reasoning.

The alternative is of course to rely on PEP-723 which provides a consistent way to define inline script dependencies but requires compatible tooling to run scripts in said manner. This also came out after this library was created.

Why "kochen"?

The initial choice of library name boiler (since this was initially a boilerplate library) was unavailable on PyPI, and so was the next choice scribbles. The next obvious step is to pick something that is unlikely to clash with other packages, i.e. boiling in German,

kochen [ˈkɔxn], verb: (Flüssigkeit, Speise) to boil [intransitive verb]

Nothing to do with Simon B. Kochen of the well-known Kochen-Specker theorem.

Download files

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

Source Distribution

kochen-0.2026.11.tar.gz (83.1 kB view details)

Uploaded Source

Built Distribution

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

kochen-0.2026.11-py3-none-any.whl (74.4 kB view details)

Uploaded Python 3

File details

Details for the file kochen-0.2026.11.tar.gz.

File metadata

  • Download URL: kochen-0.2026.11.tar.gz
  • Upload date:
  • Size: 83.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kochen-0.2026.11.tar.gz
Algorithm Hash digest
SHA256 1f1c543b3e86ade59895c15fc4e23fb525198cebaf32942b849505dd81863c2f
MD5 68311b53dca6298f4327ad24b36c4f2a
BLAKE2b-256 38528f2f5dae3bc25cf3099b349be3f371490f9c3ca971cecd5817f8d082a229

See more details on using hashes here.

Provenance

The following attestation bundles were made for kochen-0.2026.11.tar.gz:

Publisher: release.yml on pyuxiang/kochen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kochen-0.2026.11-py3-none-any.whl.

File metadata

  • Download URL: kochen-0.2026.11-py3-none-any.whl
  • Upload date:
  • Size: 74.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kochen-0.2026.11-py3-none-any.whl
Algorithm Hash digest
SHA256 7c693b735b8bbef3599f2552784c2a3cb22c0c781740319a6ec298c5cc531da9
MD5 b30cc90ecd8c1aa1775b735e28a0aba4
BLAKE2b-256 c56c8459ae49e451189286ecef45d370c687e7bb39b9d41afbd41a0dfd989d3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kochen-0.2026.11-py3-none-any.whl:

Publisher: release.yml on pyuxiang/kochen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2026.11 This release

2 files

0.2026.10

2 files

0.2026.9

2 files

0.2026.8

2 files

0.2026.7

2 files

0.2026.6

2 files

0.2026.5

2 files

0.2026.4

2 files

0.2026.3

2 files

0.2026.2

2 files

0.2026.1

2 files

0.2025.15

2 files

0.2025.14

2 files

0.2025.13

2 files

0.2025.12

2 files

0.2025.11

2 files

0.2025.10

2 files

0.2025.9

2 files

0.2025.8

2 files

0.2025.7

2 files

0.2025.6

2 files

0.2024.5

2 files

0.2024.1

1 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