Show HN: Colnade – Type-Safe DataFrames for Python (github.com)

3 points by jwde ↗ HN
Colnade is an expression-building and translation layer that sits on top of DataFrame backends like Polars, Dask, and Pandas to provide lint-time safety.

Colnade replaces string-based column references with typed class attributes:

```

import colnade as cn

class Users(cn.Schema):

    name: cn.Column[cn.Utf8] = cn.Field(pattern=r"^[a-zA-Z\s\-']+$")

    age: cn.Column[cn.UInt64] = cn.Field(ge=0, le=150)

    score: cn.Column[cn.Float64] = cn.Field(ge=0, le=100)

# Users.naem → type error in your editor

# Users.name.sum() → type error (string column)

df.filter(Users.age > 25).sort(Users.score.desc())

```

Colnade is pure Python with no plugins. Backend adapters for Polars, Pandas, and Dask are included today, and the protocol is open to support other backends.

For schema-modifying operations like `select` and `agg`, Python's type system can't infer output schemas- Colnade handles this with explicit re-binding (`cast_schema`) and optional runtime validation, along with Pydantic-style `Field` constraints for domain invariants.

I started building this because time and time again I've found DataFrame operations to be the weakest part of data science & ML projects from a type safety standpoint.

The project is still quite new so the API is likely to continue to evolve quickly, but I'd love any feedback!

Docs: https://colnade.com/

Source: https://github.com/jwde/colnade

2 comments

[ 0.26 ms ] story [ 19.9 ms ] thread
pure python is legit! excellent documentation