Skip to main content

cobol-parser

Python library for parsing IBM Enterprise COBOL source into an AST. Supports dependency extraction, dead code detection, program flow analysis, and CRUD matrices. 99.1% parse success on the NIST COBOL-85 corpus.

Python 3.11+ Tests Coverage License: AGPL v3

Install

pip install -e ".[dev]"

Requires Python 3.11, 3.12, or 3.13.

Install the CLI globally (uv)

To get the cobol-parser command on your PATH in any directory, without setting up a project virtualenv:

uv tool install .            # from a clone of this repo
uv tool install --editable . # dev mode: picks up code changes without reinstalling

The install is pure Python by default: no C compiler needed. The optional Cython accelerators (about 3x lexer throughput) are an opt-in, chosen by one environment variable both when building and when running:

COBOLPARSER_ACCEL=1 uv tool install . --reinstall   # compile them
export COBOLPARSER_ACCEL=1                          # and use them

The PyPI wheels already contain the compiled accelerators, so for a pip install cobol-parser setting COBOLPARSER_ACCEL=1 at run time is enough. Without the variable, a compiled extension is ignored.

Verify it worked from anywhere:

cobol-parser --version

After pulling new commits (non-editable install only), rerun uv tool install . --reinstall to update.

Quick Start

from cobolparser import parse_cobol

result = parse_cobol(source, filename="prog.cbl")
if result.success:
    print(result.ast.program_name)
    print(result.ast.to_json())

CLI:

cobol-parser parse program.cbl
cobol-parser analyze program.cbl      # dynamic call analysis
cobol-parser dead-code program.cbl    # unreferenced paragraphs
cobol-parser lint program.cbl         # every analyzer at once, as one list

Lint a program

lint runs several analyzers over a single parse and reports everything they found as one severity-graded list, instead of one subcommand (and one re-parse) per concern:

cobol-parser lint program.cbl --format text
program.cbl:6:1: warning [unused-variables] WORKING-STORAGE item WS-NEVER-USED (level 01) is never referenced in the PROCEDURE DIVISION
program.cbl:12:5: error [move-type-check] Illegal MOVE: cannot move NUMERIC item 'WS-COUNTER' to ALPHABETIC item 'WS-ALPHA'
program.cbl:17:1: warning [dead-code] paragraph ORPHAN-PARA is never referenced
3 finding(s): 1 error, 2 warning, 0 info (7 rule(s) ran)

--rule narrows the run (rule ids are the analyzer subcommand names), --min-severity narrows the output, and --fail-on error exits 3 when anything at that severity was reported — a CI gate that stays distinct from exit 1, which still means the run itself failed. --format json (the default) additionally reports which rules ran, which raised, and what could not be checked, so a quiet report is never mistaken for a clean program.

from cobolparser import LintAnalyzer, parse_cobol

report = LintAnalyzer().analyze(parse_cobol(source, filename="prog.cbl").ast)
for finding in report.findings:
    print(finding.rule, finding.severity, finding.message)

Generate test data from a copybook

gen-data turns a copybook record layout into a CSV of synthetic records — one column per elementary field, values that always fit the field's PICTURE, USAGE, and level-88 domain:

cobol-parser gen-data CUSTOMER.cpy --rows 100 --seed 7 -o customers.csv
from cobolparser.generators import CopybookDataGenerator, DataGeneratorOptions

dataset = CopybookDataGenerator(
    DataGeneratorOptions(rows=100, seed=7)
).generate_from_file("CUSTOMER.cpy")
print(dataset.to_csv())

A seed makes output byte-identical across runs; omit it and the seed that was drawn is reported on dataset.seed (and by gen-data --describe) so any run can be replayed. REDEFINES and FILLER are excluded by default, and OCCURS tables expand to one column per occurrence.

Commands

# Tests
python -m pytest tests/ -v
python -m pytest --cov=cobolparser --cov-report=html

# Lint / format / type-check
ruff check .
black .
mypy cobolparser/

Documentation

Full reference: .okf/index.md

License

GNU Affero General Public License v3.0 or later — Copyright © 2026 Samuel Dion. See LICENSE.

Metadata

Release files for cobol-parser 3.1.1

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

Source distribution (sdist)

Source distribution for cobol-parser 3.1.1
File Size Uploaded Provenance Actions
cobol_parser-3.1.1.tar.gz 1.6 MB With provenance Details for cobol_parser-3.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for cobol-parser 3.1.1
File Actions
cobol_parser-3.1.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for cobol_parser-3.1.1-cp313-cp313-win_amd64.whl
cobol_parser-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for cobol_parser-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cobol_parser-3.1.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for cobol_parser-3.1.1-cp313-cp313-macosx_11_0_arm64.whl
cobol_parser-3.1.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for cobol_parser-3.1.1-cp312-cp312-win_amd64.whl
cobol_parser-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for cobol_parser-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cobol_parser-3.1.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for cobol_parser-3.1.1-cp312-cp312-macosx_11_0_arm64.whl
cobol_parser-3.1.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for cobol_parser-3.1.1-cp311-cp311-win_amd64.whl
cobol_parser-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for cobol_parser-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cobol_parser-3.1.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for cobol_parser-3.1.1-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 17.4 MB

Release files / cobol_parser-3.1.1.tar.gz

Download URL cobol_parser-3.1.1.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
db268251468a0db4835e8ecb5d6fbeb3cc633d08908eecb574c3aaa4a408dae7
BLAKE2b-256 checksum
How to use checksums
c1f2174beb7a6fdae63c06d0f727613afad256bbea2d53f78665189c55bfac89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp313-cp313-win_amd64.whl

Download URL cobol_parser-3.1.1-cp313-cp313-win_amd64.whl
Size 1.5 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
be7f9989d9a753d6a7efd25f47829012f24a09d586620d780fe1b2e9eac795f5
BLAKE2b-256 checksum
How to use checksums
4024fa175eba0b71a8b10cb396b9e3620dce4deca92a95f674c8f540a806d3ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cobol_parser-3.1.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7c7d0d41b76d416e0c7ffa8da77761b3f1dbffd3d9a93a235f79c5a4719f414f
BLAKE2b-256 checksum
How to use checksums
87166aee1f2cd4161bf9dbfe798765d09add1eda562c7101456201a5e4578501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL cobol_parser-3.1.1-cp313-cp313-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0c9fe5be636694159ddf920f7404b95e4bd5ec96a0d73dd2a2c0dd9a0ad17f8f
BLAKE2b-256 checksum
How to use checksums
066c13628881db1c17c3ccf09c3b413c5ed0adc064f3bdb36832299e00622143
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp312-cp312-win_amd64.whl

Download URL cobol_parser-3.1.1-cp312-cp312-win_amd64.whl
Size 1.5 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
bb994d77245ef5c907072aaed66c2c7bde0eb10c050c8ee27d3cebfd66c8f6d4
BLAKE2b-256 checksum
How to use checksums
955c4a8d7a711f034b0851cc7bb87edc0c44afc57cf92a4aefb36c9813609ea2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cobol_parser-3.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7a7f20753c2a97921f160dba1619976948e3205ae07e9318485bdd1156bd9e29
BLAKE2b-256 checksum
How to use checksums
43d4395cb065518bc291f9cdc0065b34b808e1cdaf515a05fc47746a55a05b87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL cobol_parser-3.1.1-cp312-cp312-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e948d6c6a5d7ccc3ed33d3f7c22fea93ba7a16faa7603eb46ba23bdbf4be5ca2
BLAKE2b-256 checksum
How to use checksums
437894d28143e1f4b583e9424e96ba70ef0c5b33ee65ca028180a2395e557040
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp311-cp311-win_amd64.whl

Download URL cobol_parser-3.1.1-cp311-cp311-win_amd64.whl
Size 1.5 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
850fd1230c9d80281adb985159ddc124cf1daa83be62c26974e9b3419fbb486f
BLAKE2b-256 checksum
How to use checksums
a5fe041983dc05654f04aadfe071357398158b1191c1b10db0197d16ca634d45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cobol_parser-3.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
724e0f97bf51bc7b0dee74062aed902b12087d3e882b3fc237ce7cd80512274a
BLAKE2b-256 checksum
How to use checksums
6f5d2dede9af01a24564e0d53d8a0a5870d7a4b570d393db1d6ff4d496bd7859
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / cobol_parser-3.1.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL cobol_parser-3.1.1-cp311-cp311-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e0d8800fdf7ea785264a9ade392df933ab270c6d8435f56b655aa2ef77a4ee0f
BLAKE2b-256 checksum
How to use checksums
2b0037fb732b83f9814bfb6672d010af29e42962eb986b970713244927c7ccb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for cobol-parser 3.1.1

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.

Full provenance

All 10 files in this release have been uploaded with provenance metadata.

Select from 10 files

Attestation for cobol_parser-3.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

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