Skip to main content

PyPI version Build Status License: MIT Documentation Status PyPI - Downloads

canml

canml is a Python toolkit for decoding of CAN bus logs (BLF) using CAN.DBC definitions. It streams large BLF files into pandas DataFrames—either in chunks or all at once—and offers robust CSV and Parquet export, signal‐level filtering, DBC merging, and progress reporting.


Key Features

Configurable BLF loading via CanmlConfig (chunk size, progress bars, uniform timing, interpolation, sorting)

DBC management with caching: merge one or many .dbc files, auto-detect collisions, optional signal-name prefixing, and LRU caching for repeated loads

Streaming BLF decode with iter_blf_chunks()—filter by arbitration ID or by signal name, and emit tidy pandas chunks without blowing up memory

One-call full-file load with load_blf()—ID or signal filters, uniform timestamp spacing (with raw backup), missing-signal injection (dtype-safe), linear interpolation, and automatic enum→Categorical conversion

Rich metadata support: pull any custom DBC attributes into df.attrs['signal_attributes'] and carry them through to exports

Incremental CSV & Parquet export: auto-create directories, write in append mode, and side-dump your signal_attributes JSON alongside your data

Built-in logging & progress bars (Python logging + tqdm) to keep you informed without clutter


Installation

pip install canml

Dependencies:

  • Python ≥ 3.8, < 4.0
  • cantools ≥ 39.4.4
  • python-can ≥ 4.4.0
  • pandas ≥ 2.2.2
  • numpy ≥ 1.26.4
  • tqdm ≥ 4.0.0
  • pyarrow ≥ 11.0.0

Usage Quickstart

from canml.canmlio import load_dbc_files, load_blf, to_csv, to_parquet, CanmlConfig

# 1️⃣ Load your DBC(s) (namespace-collision safe)
#    If you have multiple, pass a list; prefix_signals avoids any name clashes.
db = load_dbc_files("vehicle.dbc", prefix_signals=True)

# 2️⃣ Stream-decode the BLF in memory (no CSV yet)
#    Use CanmlConfig to tweak chunk size, uniform-timing, interpolation, etc.
cfg = CanmlConfig(
    chunk_size=5000,        # rows per chunk
    force_uniform_timing=True,
    interval_seconds=0.01,
    progress_bar=True
)
df = load_blf(
    blf_path="drive.blf",
    db=db,
    config=cfg,
    expected_signals=["Engine_RPM", "Brake_Active"]
)

# 3️⃣ Inspect your DataFrame
print(df.head())
#     timestamp  Engine_RPM  Brake_Active  raw_timestamp
# 0        0.00       1200.0           0.0       162523.1
# 1        0.01       1230.0           0.0       162523.2
# …

# 4️⃣ Export to CSV (with metadata JSON)
to_csv(
    df,
    output_path="drive_data.csv",
    metadata_path="drive_data_signals.json"
)

# 5️⃣ Or write Parquet (faster reads/writes + metadata)
to_parquet(
    df,
    output_path="drive_data.parquet",
    metadata_path="drive_data_signals.json"
)

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository on GitHub.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request with a clear description of your changes.
  4. To update the docu:
pip install sphinx sphinx-rtd-theme

Please open an issue to discuss major changes before starting work.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits

  • Inspired by cantools and python-can for CAN bus parsing.
  • Built using pandas, NumPy, scikit-learn, and matplotlib for data manipulation, machine learning, and visualization.
  • Special thanks to the Python community for their open-source contributions.

Contact

For questions or support, please open an issue on the GitHub repository.

Metadata

Release files for canml 0.1.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for canml 0.1.14
File Size Uploaded Provenance Actions
canml-0.1.14.tar.gz 16.2 kB Without provenance Details for canml-0.1.14.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for canml 0.1.14
File Interpreter ABI Platform Actions
canml-0.1.14-py3-none-any.whl Python 3 none any Details for canml-0.1.14-py3-none-any.whl

Total release size: 25.9 kB

Release files / canml-0.1.14.tar.gz

Download URL canml-0.1.14.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cfe1e899aeb29993d7cbcd95923d9af9c3381c06a34a50f539c1f1fca4fd05c3
BLAKE2b-256 checksum
How to use checksums
f3185ac1be1268b846b0e65cffeaad1156bee3840dbe0a2c6e20b8ac83a0dc91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Release files / canml-0.1.14-py3-none-any.whl

Download URL canml-0.1.14-py3-none-any.whl
Size 9.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3b5aeda22ccc7149945852a9a4bf5c18fe61f56577c8bd7a6959158faf017f7
BLAKE2b-256 checksum
How to use checksums
e31be4fdc4936e7ebb9eae9c2a3b730cfee5720480584434ad350af2f058781f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.10

Security for canml 0.1.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page