Show HN: Bydantic – Pydantic-style bitfields for Python

Hi HN! I’d like to share Bydantic, a Python library for declaratively defining bitfields using Python type hints and dataclass-like field types. It automatically handles serialization and deserialization, so you can focus on structure, not boilerplate.

I built Bydantic while reverse-engineering the Bluetooth protocol used by a family of inexpensive HT radios [1]. The protocol was messy and complex, and I quickly got tired of writing ad hoc parsing and packing code. What I really wanted was something like Pydantic—but for binary data. So I made this!

Finding the right balance between expressiveness and type safety was a big challenge, especially with the limits of Python’s type hinting system. But I’m really happy with how it turned out.

It’s implemented in pure Python and so should work on MicroPython, though I haven’t tested that yet.

I’d love to hear if this might be useful in your own projects—or if there are features you wish it had. Thanks for taking a look!

[1] https://kylehusmann.com/benlink

1 points khusmann 1 year ago 0 comments

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton