leb128
LEB128(Little Endian Base 128)
What it is and what it does
LEB128 is a variable-length integer encoding scheme that compresses arbitrarily large integers into a small number of bytes. This package provides Python functions to encode and decode both signed and unsigned integers in LEB128 format, with support for streaming decoding via file-like objects.
The format is used in two major contexts: DWARF debug information (used by debuggers and profilers) and WebAssembly binary encoding (for all integer literals in WASM modules). If you're working with either of these formats or need compact integer serialization, this library handles the encoding/decoding mechanics so you don't have to implement them yourself.
Use it for:
- Parse or generate WebAssembly binary modules that use LEB128 for integer encoding.
- Read DWARF debug information from compiled binaries for debugging or analysis tools.
- Serialize integers compactly in custom binary protocols or file formats.
- Decode streaming integer data from file-like objects without loading entire buffers.
- Handle both signed and unsigned integer encoding in a single library.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Encodes and decodes integers using LEB128 (Little Endian Base 128), a variable-length compression format used in DWARF debug files and WebAssembly binary encoding.
Yes. The package is actively maintained, has no dependencies, installs cleanly, carries a permissive MIT license, and solves a specific technical problem (LEB128 encoding/decoding) that you would otherwise need to implement yourself. Use it if you're working with WebAssembly, DWARF debug formats, or need LEB128 compression in your own binary protocols.
Install
leb128 on PyPI
pip
pip install leb128uv
uv add leb128poetry
poetry add leb128Installing leb128
Before you install
Low friction: pure Python wheel with no runtime dependencies. Last commit 2026-03-27 and active maintenance status.
License in practice
MIT License permits unrestricted use, modification, and distribution with only attribution and liability disclaimer required.
Quickstart
import leb128
import io
# Unsigned encoding/decoding
assert leb128.u.encode(624485) == bytearray([0xe5, 0x8e, 0x26])
assert leb128.u.decode(bytearray([0xe5, 0x8e, 0x26])) == 624485
# Signed encoding/decoding
assert leb128.i.encode(-12345) == bytearray([0xc7, 0x9f, 0x7f])
assert leb128.i.decode(bytearray([0xc7, 0x9f, 0x7f])) == -12345
Package facts
| License | MIT License Copyright (c) 2021 Mohanson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in… (full text in the JSON record) (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 217 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,543,677/month — #2,581 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: leb128-1.0.9-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
fixedintProvides fixed-width integer classes that…
permissive · top 5,000 on PyPI
bech32mEncodes and decodes Bech32 and Bech32m strings,…
permissive · top 15,000 on PyPI
bitarray-hardbyteProvides an efficient C-backed array type for…
permissive · top 15,000 on PyPI
rlpEncodes and decodes data using Recursive Length…
permissive · top 5,000 on PyPI
base36Converts integers to and from base36…
permissive · top 15,000 on PyPI
cintWraps ctypes integer types to perform…
permissive · top 5,000 on PyPI
ecojiEncodes and decodes binary data as sequences of…
permissive · top 15,000 on PyPI
overpunchParses and formats overpunch-encoded numbers, a…
permissive · top 15,000 on PyPI
base58checkEncodes and decodes byte arrays using the…
permissive · top 15,000 on PyPI
pylzsspylzss decodes and encodes data compressed with…
copyleft · top 15,000 on PyPI