Skip to main content

cobol-parser

A COBOL parser for Python with an IBM Enterprise COBOL focus. It turns COBOL source into a traversable AST (JSON export, error recovery, copybook expansion with a source map back to the original lines), and builds static analyzers, test-data generators, a z/OS JCL front end and an MCP server for AI agents on top of it.

458 of the 459 NIST COBOL-85 programs in examples/cobol/ parse cleanly (the one that does not, SM101A, needs its copybooks expanded first).

Python 3.11+ PyPI Coverage License: AGPL v3

Install

pip install cobol-parser                # the library and the cobol-parser CLI
pip install 'cobol-parser[mcp]'         # plus the MCP server
pip install 'cobol-parser[jcl]'         # plus JCL (through jcl-parser)

Requires Python 3.11, 3.12 or 3.13. The core library has no runtime dependencies. Optional extras:

Extra Adds
mcp cobol-parser mcp, the MCP server (docs/mcp-server.md)
jcl cobol-parser jcl, and the JCL joins in field-impact, widen-check and the MCP server
pl1, hlasm PL/I and assembler programs in the MCP server's call graph
fast Cython, to build the optional accelerators from source
dev, docs the test, lint and docs toolchain for working on this repo

To get the CLI on your PATH without a project virtualenv:

uv tool install cobol-parser
uv tool install --editable .   # from a clone, picking up code changes

The install is pure Python by default. The PyPI wheels also carry three compiled Cython accelerators (about 3x lexer throughput), used only when COBOLPARSER_ACCEL=1 is set at run time. From a clone, the same variable at build time compiles them:

pip install -e ".[fast]"
COBOLPARSER_ACCEL=1 python setup.py build_ext --inplace
export COBOLPARSER_ACCEL=1

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())
for error in result.errors:
    print(error)

parse_cobol stops at the first error by default. To collect every error and keep going, use CobolParser(error_recovery=ErrorRecoveryMode.COLLECT_ALL). To expand COPY statements, use parse_cobol_with_expansion(source, "prog.cbl", copybook_paths=["copybooks"]).

Every analyzer has the same shape, <Analyzer>().analyze(ast), and returns a report with to_dict():

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)

What it does

The CLI has one subcommand per analyzer or generator. Every subcommand emits JSON by default, and takes --help with examples and its exit codes. The full list, with every flag, is in .okf/cli.md.

Check a program

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

lint runs nine analyzers over one parse: dead code, unused variables, MOVE type checks, I/O sequencing, LINKAGE checks, recursion risk, complexity, DCLGEN and SQL/CICS checks. --rule narrows the run, --min-severity the output, and --fail-on error exits 3 when a finding at that severity was reported, so it can gate a build. Each analyzer is also its own subcommand (dead-code, xref, program-flow, complexity, health, ...).

Check a whole codebase

cobol-parser scan --glob 'src/**/*.cbl' --analyzer health --clones --cache-dir .cache
cobol-parser call-check src/ --copybook-path copybooks --fail-on error
cobol-parser codebase-graph src/ --format mermaid
  • scan runs analyzers over many files in one process, with per-file fault isolation and cross-file duplicate-paragraph detection. With --cache-dir, a file whose source, copybooks and copybook directories are unchanged reuses its report from the last run.
  • call-check checks every CALL against the PROCEDURE DIVISION USING or ENTRY it reaches in another file: argument count, passing mode (BY VALUE / BY REFERENCE), byte length, USAGE and RETURNING. A dynamic CALL is checked against every target its variable can hold.
  • codebase-graph and copybook-impact give the call graph and the programs each copybook reaches.

Plan a change

cobol-parser lineage prog.cbl --field CUST-BAL
cobol-parser field-impact CUST-ID src/ --jcl jcl/
cobol-parser widen-check CUST-ID src/ --to '9(9)'
cobol-parser diff old/prog.cbl new/prog.cbl
  • lineage follows one field's values through a program, and field-impact follows them across programs, files, DB2 columns and JCL datasets.
  • widen-check answers "what breaks if CUST-ID becomes PIC 9(9)": every field downstream that would truncate the wider value, and, when the byte length changes, the records whose later fields shift, the REDEFINES that overlay it, the files whose LRECL changes (and the other programs reading the same dataset), and the CALL / LINKAGE records on both sides.
  • diff compares two versions by structure, so reformatting and sequence numbers are no change.

SARIF for code scanning

lint, call-check and scan take --format sarif and write a SARIF 2.1.0 log, which GitHub code scanning and IDE problem panes read directly:

cobol-parser lint prog.cbl --format sarif -o lint.sarif
cobol-parser scan --glob 'src/**/*.cbl' --format sarif -o scan.sarif

Generate and read test data

cobol-parser gen-data CUSTOMER.cpy --rows 100 --seed 7 -o customers.csv
cobol-parser decode CUSTMAST.dat --copybook CUSTOMER.cpy --charset ebcdic
cobol-parser compare expected.dat actual.dat --copybook CUSTOMER.cpy --key CUST-ID
cobol-parser gen-fixtures prog.cbl --scenarios all -o bundle.json

gen-data writes synthetic records that fit each field's PICTURE, USAGE and level-88 values (a seed makes the output byte-identical across runs). decode and compare read record images, ASCII or EBCDIC, fixed or variable-length. gen-fixtures builds a test bundle for a whole program: one scenario per reachable branch, the values each mocked file, CALL, SQL or CICS boundary supplies, and the expectations to assert. Its schema is in docs/fixture-bundle-schema.md.

Give an AI agent exact answers

pip install 'cobol-parser[mcp]'
claude mcp add cobol -- cobol-parser mcp --root /path/to/checkout

cobol-parser mcp is a read-only Model Context Protocol server. Its tools answer "what is this program", "what is this field and where is it used", "who calls this", "what does a change to this copybook reach" and "show me this paragraph", with a file:line for every fact and a list of what they could not check. See docs/mcp-server.md.

The repo also ships a cobol-analysis agent skill (.claude/skills/cobol-analysis/SKILL.md) that teaches an agent which subcommand answers which question.

Project config

A cobol.yml at the project root sets copybook directories, source format, >>DEFINE symbols, data encodings and lint defaults once, for every subcommand. cobol-parser config shows which file is in effect. See docs/project-config.md.

Language coverage

IBM Enterprise COBOL through 6.4: fixed and free format, COPY ... REPLACING and REPLACE, conditional compilation (>>DEFINE, >>IF, >>EVALUATE), nested and contained programs, object-oriented CLASS-ID / METHOD-ID, user-defined functions (FUNCTION-ID), DECLARATIVES, Report Writer, XML and JSON statements, and EXEC SQL, EXEC CICS and EXEC DLI blocks. One program per IBM program type (batch, VSAM, CICS, IMS, DB2, MQ, ...) runs through the whole stack in the test suite; the matrix is in docs/enterprise-program-types.md.

Documentation

For Read
Using the MCP server docs/mcp-server.md
The cobol.yml project config docs/project-config.md
The gen-fixtures bundle format docs/fixture-bundle-schema.md
Every subcommand and flag .okf/cli.md
How the library works, area by area .okf/index.md
What the backend and mocky-mock rely on interface-contract.md
What changed in each release CHANGELOG.md
Everything under docs/, including design plans docs/README.md

The .okf/ folder is the reference documentation: one topic file per area (lexer, parser, analyzers, generators, CLI, MCP, tests), written so that a person or an AI agent loads only the file for the task at hand. scripts/okf_check.py checks what those files claim against the code.

Development

pip install -e ".[dev,docs]"
git config core.hooksPath .githooks              # the OKF pre-commit check

python -m pytest tests/ -q -n 4 --no-cov         # fast full run
python -m pytest tests/                          # with the 90% coverage floor
COBOLPARSER_PERF=1 python -m pytest tests/performance/test_large_program.py   # 40k-line perf lane

python -m ruff check .
python -m black .
python -m mypy cobolparser/

CI runs only on manual dispatch (.github/workflows/ci.yml has no push or PR trigger), so run lint, types and the full suite locally before pushing. Measure coverage on the pure-Python build: with COBOLPARSER_ACCEL=1, coverage.py cannot see the code the compiled modules replace. Test layout and markers: .okf/tests.md.

License

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

Metadata

Release files for cobol-parser 3.3.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.3.1
File Size Uploaded Provenance Actions
cobol_parser-3.3.1.tar.gz 1.7 MB With provenance Details for cobol_parser-3.3.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for cobol-parser 3.3.1
File Actions
cobol_parser-3.3.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for cobol_parser-3.3.1-cp313-cp313-win_amd64.whl
cobol_parser-3.3.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.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cobol_parser-3.3.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for cobol_parser-3.3.1-cp313-cp313-macosx_11_0_arm64.whl
cobol_parser-3.3.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for cobol_parser-3.3.1-cp312-cp312-win_amd64.whl
cobol_parser-3.3.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.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cobol_parser-3.3.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for cobol_parser-3.3.1-cp312-cp312-macosx_11_0_arm64.whl
cobol_parser-3.3.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for cobol_parser-3.3.1-cp311-cp311-win_amd64.whl
cobol_parser-3.3.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.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
cobol_parser-3.3.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for cobol_parser-3.3.1-cp311-cp311-macosx_11_0_arm64.whl

Total release size: 19.4 MB

Release files / cobol_parser-3.3.1.tar.gz

Download URL cobol_parser-3.3.1.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
537ca01de329aae5b5c94aa23167c59577e2d23eaee28763758d76810299013f
BLAKE2b-256 checksum
How to use checksums
015498276f0515ca5511875f3c6d5182358161dea21d6d9889ebb9f61b542540
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp313-cp313-win_amd64.whl
Size 1.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
ec9cddb64e7a0598059d3a09256cd38a1cd9ba6a2c3ec78ae5f37370f0cd21f5
BLAKE2b-256 checksum
How to use checksums
46ea2b587403e70b1729027ade7df6720c04dbf4765f1f7cfcdb516a7fd6e77b
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a1d4689442acdee1f97cf63eb85521c8d7ec9a17e5c94616e529e91551bbe67b
BLAKE2b-256 checksum
How to use checksums
ddc1ec2e9183cef616585675e023ef72453ba63ac9145a2bf9d13b4273d0d88a
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp313-cp313-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b78a6d914d9ca42179556419c368f81cde733aaf03079545d489e2ec1830e3cc
BLAKE2b-256 checksum
How to use checksums
f9da243412f5d12be82d0fd5abab94da49ccdbabb12c9aedc2593d1f83e1e504
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp312-cp312-win_amd64.whl
Size 1.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
af1e852af0201ebea1a17932ede44a7599002a894694913dd4b4b55d30858980
BLAKE2b-256 checksum
How to use checksums
3e04c1836eabb96f3ca78a7d6c09c233b96244ecd514d0dbeb42e7c3c7dc212b
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9d157e435cd072acc1b45e24c3314e29f0588bc1446eb92efe8b92b7ed0094c7
BLAKE2b-256 checksum
How to use checksums
e28b573e21a3bfe7ba099922593fcbe688543dbe3510f25cce6badc59d22805e
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp312-cp312-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
466da9d35714826fa44fa41724bb0292c1ad1c98f8458c5ff7fb8587cb9ca869
BLAKE2b-256 checksum
How to use checksums
2c031102b707ff6664951ffff798c1a1f381b594181b5288db13397b50a76407
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp311-cp311-win_amd64.whl
Size 1.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
186a8ee6a4e170238b11c152e276097d696edd990e424d4035ab8ed5f317db01
BLAKE2b-256 checksum
How to use checksums
ea702a4e493a27d3d60e2cb8615a872b03ba7b6212e523db839fb33c663877be
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.5 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
e42950396fcc72f24fe2315258b9ae9eaafc63b5e723ceb9c077af5687e91172
BLAKE2b-256 checksum
How to use checksums
5f3b2d13bc08141dd667647367594162ffb5793df4a3a858a2e2ae71681d906c
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 Nov 2, 2026.

Transparency log

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

Download URL cobol_parser-3.3.1-cp311-cp311-macosx_11_0_arm64.whl
Size 1.7 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d80f7667d956460ef3b9f989300f7bbdfd2444c66a74dbe8570c3cfbce7ca081
BLAKE2b-256 checksum
How to use checksums
2b7bc96e0af109aeb1da8cc287c333cacd331b5d6a9d7f86c1981201c3b60ba7
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 Nov 2, 2026.

Transparency log

Security for cobol-parser 3.3.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.3.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 Nov 2, 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