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.0

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.0
File Size Uploaded
cobol_parser-3.1.0.tar.gz 1.4 MB Details

Built distributions (wheels)

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

Total release size: 16.3 MB

Release files / cobol_parser-3.1.0.tar.gz

Download URL cobol_parser-3.1.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
39ba232a69ecb84a9bc0ad5f4eefcf6ce85b45b7b3a7248d6293aae3fc13e777
BLAKE2b-256 checksum
How to use checksums
cf7701d584f3dcfadc8e6c4448db6b37973d38e7a7ed12aea945887305d21d55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp313-cp313-win_amd64.whl
Size 1.4 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
21c5e833770240f364a6bcfdf01079b2b7be6c90a5a7828f2df8bdf9a5157ade
BLAKE2b-256 checksum
How to use checksums
5c67df8fc18ae20bf20f3b11d383c03c86493d91c3e8b581d7d8aea7a68f6fbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
afc728e45854f2fec13dbf212b83ae835257d3b66d9e1abfd6f2f6f8906b5472
BLAKE2b-256 checksum
How to use checksums
bc6f9b9973938c926b4adbd53ac28b5fce4f48badf33ab01a042ad126ebb9f17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp313-cp313-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cbeeefdf6b376f55a8da2f7abe5c883bad03d885b230dbdb663ddad95915689b
BLAKE2b-256 checksum
How to use checksums
2c7e1c794ba89c4f40ca2e237fef0a87562a1bfc5a5571b2b54ae4a843b56111
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp312-cp312-win_amd64.whl
Size 1.4 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
4aabfacec91de08ece00950c374a694e104288d71d48e285c6a4bf738e95567d
BLAKE2b-256 checksum
How to use checksums
3ad262eb6fd583c73cb3818bfdecc6cfda6ec51ee910b700aac755df3dd9c6bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
aa34a31c2a579da473beabb5a26f4addf1c3896769453e8a9e9da4d24e848341
BLAKE2b-256 checksum
How to use checksums
1f1e5352b16f136fbb7f489f33366852c177e6e5137d6361340bd88407d54cb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp312-cp312-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ff5daede393bf04a464bded0e4935b935ca0cc076bda55db2b13eaf148a5d60a
BLAKE2b-256 checksum
How to use checksums
f14e76cda859533c55ba5db09798172a2655d389e9304600f3ed5c8fa5b4fbd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp311-cp311-win_amd64.whl
Size 1.4 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c31e64cbd64fc807a24f4fdefb58b40b6133d47ca94f813fb04ada0034550304
BLAKE2b-256 checksum
How to use checksums
3df9fbd317802b5a9d6be6998c9d886d2513c57c568bd69c1b6736381b2968c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.2 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a4fee8c6562dc6d89c41e2b0c556ad4c046ea8236829ac1d04468957c51527d4
BLAKE2b-256 checksum
How to use checksums
3a4c64ded3bc51e22f2a7340f7b1296296e7fae0fab952848b716c9283e89ffc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

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

Download URL cobol_parser-3.1.0-cp311-cp311-macosx_11_0_arm64.whl
Size 1.4 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f3ec9a3e0b58803be401ef16c8514d212e1a300942ee9dcbc0d7b9535393e1d9
BLAKE2b-256 checksum
How to use checksums
215e3113b4d38135c787efa88be16516e67828aa8d51fd3b62c19b9ecfe1a347
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.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.

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 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.1.0 This release

10 release files

3.0.0

10 release files

2.0.1

10 release files

2.0.0

10 release files

1.8.4

9 release files

1.8.2

9 release files

1.8.0

9 release files

1.7.8

9 release files

1.7.7

9 release files

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