Skip to main content

Biosensor

A lightweight Python package with an attached local viewer that converts raw electrochemical instrument exports into one tidy dataframe schema, and lets you visually verify the parse before trusting the output.

Targets solo researchers and small labs working on immunosensor and biosensor cyclic voltammetry (CV) / DPV / SWV data who need a fast, local path from raw instrument export to usable data, without adopting an institutional ELN.

Supported formats (v1)

  • CH Instruments text export
  • Metrohm Nova (Autolab) text/CSV export
  • PalmSens .pssession (best-effort; see src/biosensor/readers/palmsens.py)
  • Generic delimited CSV: a named header, metadata lines before the header, or headerless two-column numeric (potential, current)

Format detection is content-based (file signature and header content), not filename-extension based.

Install

The library, from PyPI (pandas is its only dependency):

pip install biosensor

Flask and traceact are the viewer's dependencies, not the library's, so they install only with the viewer extra. The viewer, launchers, and sample_data/ ship in the repository, not the wheel; clone and install in place for those and the test suite:

python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,viewer]"

Library usage

from biosensor import load, batch_load, to_dataframe

result = load("cv01.txt")
df = to_dataframe(result.measurement)
print(result.qc.sanity_status)  # "ok" | "flagged" | "failed"

batch = batch_load("data/2026-08-05-run/")
df = batch.to_dataframe()          # all files, one tidy frame
qc_df = batch.qc_dataframe()       # per-file sanity status

Every reader converts its instrument-specific format into a Measurement (potential, current, scan rate, cycle number, technique, sample ID, analyte concentration, and a flexible technique_params dict for things like SWV frequency or DPV pulse width). QC state (sanity_status, review notes) lives in a separate QCRecord so the sanity heuristic can evolve without touching the measurement schema.

Viewer

Double-click the launcher for your platform (launch.command on macOS, launch.sh on Linux, launch.bat on Windows). Each sets up the venv on first run, then starts the server and opens the browser:

./launch.command      # macOS
./launch.sh           # Linux
launch.bat            # Windows
# or manually: source .venv/bin/activate && python viewer/app.py

Opens at http://127.0.0.1:5050. Three panes: file list on the left (live filter, ok/flagged/failed tabs), the center with three tabs (the CV curve in Plotly with zoom/pan; a Dataframe tab with row search, previewing up to 2,000 rows in the page while CSV export covers the full file; and an Overlay tab), and a parse record on the right (quality check, instrument metadata, sample/concentration mapping).

One Add data button loads your files: choose one file, several files, or a whole folder, or drag any of them onto the window. Biosensor reads each one and sorts out what to show.

On the Curve tab a Baseline dropdown draws the chosen peak-current method on the curve: raw maximum (not baseline-corrected, the default), or a linear pre-peak or post-peak baseline extrapolated under the peak. The peak is marked, the measured height (ip) is drawn, and when a baseline estimate lands outside a physical range the curve says so and suggests another method. Hovering anywhere in a potential column reads out that point.

The Overlay tab draws every loaded file of the same sample on one plot, colored and ordered by concentration, with a calibration inset below it plotting peak current against concentration and a linear fit; the same peak-current methods are offered there. Correct a wrong column mapping in-place (with a live preview before applying), override the quality flag manually, and export any file or the whole batch as CSV. The open file is kept in the URL, so a reload reopens it. Light/dark theme toggle in Settings. htmx, Plotly, and the IBM Plex fonts are vendored under viewer/static/vendor/, so the viewer runs fully offline with no CDN dependency. (Fonts are IBM Plex, under the SIL Open Font License 1.1; see viewer/static/vendor/fonts/OFL.txt.)

Visual design follows the Tree Design System, with design tokens under viewer/static/tokens/.

The viewer is local, single-user, in-memory only; state resets on restart. This is intentional (see Non-goals below).

Tracing

Action-level tracing via traceact (file parse, batch upload, mapping correction, CSV export) writes to data/traces/traces.jsonl for local debugging. It isn't required to run the app, and it's gitignored.

Sanity-check heuristic (v1)

A simple curve-shape check, not anything trained: flags constant/flat current or potential (near-certain wrong column mapping), non-finite values, too few points, a single-direction sweep with no return cycle, and the absence of any peak/inflection in the current trace. Manual override is always available in the viewer.

Security

The viewer accepts arbitrary uploaded files and treats them as untrusted input:

  • Format detection inspects file content, never trusts the extension alone
  • Per-file byte and data-row limits bound parsing cost (see readers/base.py)
  • Any parse failure, including malformed or adversarial files, degrades to a per-file error, never a server crash
  • Filenames, sample IDs, and technique strings derived from file content are sanitized before display and CSV export (including a CSV-formula injection guard)
  • No macro or script execution in any format reader

Non-goals (v1)

Peak fitting, baseline correction, calibration curves, ML modeling, multi-user access, authentication, or cloud deployment. Four format readers is the v1 target, not exhaustive vendor coverage.

Sample data

sample_data/ has a synthetic 27-file batch (all four formats) for exercising the viewer by hand: an IL-6 immunosensor concentration series (CH Instruments, with sample and concentration carried in each file's contents, peak height scaling with concentration, which the Overlay tab draws as a dose-response fan), ferricyanide and blank references, Metrohm Nova DPV/CV, PalmSens sessions, a well-formed generic CSV, and two files that deliberately fail to parse (to exercise the batch error path). Point Add data → Choose a folder… at it, or drag the folder onto the window. Regenerate with:

source .venv/bin/activate
python scripts/generate_sample_data.py

Tests

source .venv/bin/activate
pytest

Fixtures in tests/fixtures/ are synthetic (generated, not instrument exports) but shaped like each format's structure, including one unrecognizable file to exercise the error path.

Documentation

Project layout

src/biosensor/       # the library: schema, readers, core API, QC heuristic
viewer/                 # Flask + HTMX + Plotly local viewer
tests/                  # pytest suite + synthetic fixtures

Author

By Mo Shehu

Release files for biosensor 1.4.0

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

Source distribution (sdist)

Source distribution for biosensor 1.4.0
File Size Uploaded
biosensor-1.4.0.tar.gz 40.5 kB Details

Built distribution (wheel)

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

Total release size: 65.4 kB

Release files / biosensor-1.4.0.tar.gz

Download URL biosensor-1.4.0.tar.gz
Size 40.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9741fa4b31e4d6a338a611ef3bab4b279040baccd60bf8fe5be8d7ee67aceb29
BLAKE2b-256 checksum
How to use checksums
7cb9009b98a63a293e171c940ce9f56f46042df988ca8e1bff298db44c2225ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / biosensor-1.4.0-py3-none-any.whl

Download URL biosensor-1.4.0-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c4ded57b302f81d470792c2b1505e8a02cb7e686ce9bb8a6060a7920e218e0e6
BLAKE2b-256 checksum
How to use checksums
95a1455bdad1ec8b0cc002a83fb1e0b950e6f00f8d26a4ca7ef6ba199a7d4cb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release history Release notifications | RSS feed

1.5.0

2 release files

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

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