btclib-org

The btclib-org organization site

View My GitHub Profile

btclib-org

Bitcoin cryptography in Python, written to be read.

btclib is a Python3 type annotated library intended for teaching, learning and using bitcoin, focused on elliptic curve cryptography and bitcoin’s blockchain. It began as a teaching tool for Ferdinando Ametrano’s Bitcoin and Blockchain Technology course — taught at the University of Milano-Bicocca, Politecnico di Milano, the University of Milano, and ESSEC (Paris) — and is used in production today. It is still marked beta, because it is still refactored whenever that makes it clearer.

What the projects here have in common is a preference for the explicit one: a public function that validates what it is handed, a docstring that states the contract rather than restating the name, and a py.typed in every package, so a caller’s own type checker reads the same annotations mypy is held to here. Where behaviour comes from a BIP, an RFC or a Bitcoin Core function, the code says so and cites it; where these libraries deviate, they say that too.

The libraries

Around them

Answering to somebody else’s vectors

A test suite that only agrees with itself proves that the code does what it does. These libraries answer to vectors their authors published: the BIPs’ and the SLIPs’ own, Bitcoin Core’s script, transaction, sighash and key-encoding files, HWI’s, Trezor’s for BIP39 and SLIP39, and Appendix A.2 of RFC 6979. Each vendored file is pinned to the upstream commit it was copied from, with a weekly job asking whether the two still agree.

Coverage is gated at 100%, so a line no test reaches is a red build rather than a number that drifts down. Everything else the repositories here are held to — one lint gate that CI runs verbatim, strict type checking, signed commits, one commit per pull request — is written down, with the reasoning and the rejected alternatives, in the repository standard.

Contributing

Questions and patches: the issues and pull requests of each repository. Its own README says where the package and the documentation are, and its CONTRIBUTING.md how a change is proposed.

What every one of them asks for is the same, and none of it waits for CI to say so: the lint gate clean, the suite passing with its coverage, a signed commit, and a changelog entry wherever a user would notice the difference.

Everything here is MIT licensed.


The btclib organization and its projects are actively supported by DGI and CheckSig.