A simple implementation of a turbo encoder and decoder
Project description
pyturbocode
pyturbocode is a Python reference implementation of turbo codes (error-correction codes used in cellular communications and deep space). The implementation prioritizes clarity over performance and provides a simple rate 1/3 code without puncturing.
The main API is the TurboCodec class, which provides a clean bytes -> bytes interface wrapping CommPy's turbo encoding/decoding functions.
Architecture
Core Component: TurboCodec
The TurboCodec class (src/pyturbocode/TurboCodec.py) is the central API with two methods:
encode(data: bytes) -> bytes: Converts input bytes to bits, passes them through a turbo encoder (rate 1/3), and returns encoded bytes with a 32-bit header storing the original bit lengthdecode(encoded_data: bytes) -> bytes: Extracts metadata from the header, performs iterative turbo decoding (default 8 iterations), and returns decoded bytes
The class uses:
- Two RSC (Recursive Systematic Convolutional) trellis instances with configurable constraint length (default K=3)
- CommPy's
turbo_encodeandturbo_decodefunctions - A random interleaver (seeded with 1346 for reproducibility)
- Bit-to-bytes conversion utilities for interfacing with CommPy
Encoding Format
The encoded packet structure:
[Original bit length: 4 bytes][Systematic stream][Non-systematic stream 1][Non-systematic stream 2]
The systematic and non-systematic streams are each equal in length to the original message bits, making the output 3x the original size (rate 1/3).
Common Commands
Package manager: Uses uv (not pip/pip-tools). Install with uv sync --all-groups.
Testing
uv run pytest # Run all tests
uv run pytest tests/test_codec.py::test_codec # Run specific test
uv run pytest -v # Verbose output
uv run pytest -k keyword # Run tests matching keyword
./all_tests.sh # Full test + docs + coverage suite
Code Quality
uv run black src/ tests/ # Format code (100 char line length)
uv run ruff check src/ tests/ # Lint with ruff
uv run pylint src/pyturbocode/ # Lint with pylint
Documentation & Coverage
uv run pdoc --html --force --config latex_math=True -o htmldoc pyturbocode
uv run coverage html -d htmldoc/coverage --rcfile tests/coverage.conf
uv run docstr-coverage src/pyturbocode
Code Style & Configuration
- Line length: 100 characters (configured in pyproject.toml for black, ruff, and pylint)
- Formatter: Black
- Linters: Ruff, Pylint
- Testing framework: Pytest with plugins (html, cov, instafail, sugar, xdist, picked, mock)
- Pre-commit hooks: Enabled (see .pre-commit-config.yaml) - runs black, ruff, and basic checks
Key Files
src/pyturbocode/TurboCodec.py- Main API (core encode/decode logic)src/pyturbocode/__init__.py- Package initialization and logging setuptests/test_codec.py- Single integration test for encode/decode roundtrippyproject.toml- Project configuration with build system, dependencies, tool configs, and dependency groups (dev, test, doc)all_tests.sh- Automation script for full test suite and documentation generation.pre-commit-config.yaml- Pre-commit hooks for code quality checks
Dependencies
Core runtime:
numpy>=2.4.2- Numerical operationsscikit-commpy>=0.8.0- CommPy library providing Trellis, turbo_encode/turbo_decode, interleavers
Python: 3.12+
Dependency groups (managed by uv):
dev: pre-commit, black, ipython, coverage-badgetest: pytest and pluginsdoc: pdoc3, genbadge, docstr-coverage
Recent Changes
The project underwent refactoring that consolidated separate modules into the TurboCodec.py API. The following modules were deprecated and removed:
rsc.py,trellis.py,siso_decoder.py,turbo_decoder.py,turbo_encoder.py,awgn.py
These functions are now accessed directly through CommPy as external dependencies.
Development Notes
- All functionality is currently in a single
TurboCodecclass - no need to navigate multiple modules - The implementation uses CommPy's high-level API; low-level encoding/decoding details are abstracted away
- Tests are minimal (single roundtrip test) - focus is on correctness of the wrapper interface
- The interleaver seed is fixed (1346) for reproducibility across encode/decode cycles
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyturbocode-0.1.13-py3-none-any.whl.
File metadata
- Download URL: pyturbocode-0.1.13-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7aa3d109b6e7732a09ed7f41742cb9b9828e9b86d0e95055455f94f45ae038e9
|
|
| MD5 |
8e5accef8e1490fadb144398337e0d9f
|
|
| BLAKE2b-256 |
180261a1f090b448ca4fa0b88c252c796bc322b755d1020dec14d728fa35d9b3
|
Provenance
The following attestation bundles were made for pyturbocode-0.1.13-py3-none-any.whl:
Publisher:
publication.yml on ydethe/turbocode
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyturbocode-0.1.13-py3-none-any.whl -
Subject digest:
7aa3d109b6e7732a09ed7f41742cb9b9828e9b86d0e95055455f94f45ae038e9 - Sigstore transparency entry: 962415543
- Sigstore integration time:
-
Permalink:
ydethe/turbocode@539726c3401d56ffbc7bad48f3f8c52f0543b888 -
Branch / Tag:
refs/tags/v0.1.13 - Owner: https://github.com/ydethe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publication.yml@539726c3401d56ffbc7bad48f3f8c52f0543b888 -
Trigger Event:
push
-
Statement type: