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.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.3.0
File Size Uploaded Provenance Actions
cobol_parser-3.3.0.tar.gz 1.7 MB With provenance Details for cobol_parser-3.3.0.tar.gz

Built distributions (wheels)

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

Total release size: 19.4 MB

Release files / cobol_parser-3.3.0.tar.gz

Download URL cobol_parser-3.3.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
68ed715ac1bd838b3bbd129ace3fbfeb60de7bac4bb76b62f08cdee0b164d3e8
BLAKE2b-256 checksum
How to use checksums
c74a444dd6b55bd05ce1fa87c2adc8a2f58bb2bed4e60d9a2c07070b43d9f13e
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.0-cp313-cp313-win_amd64.whl

Download URL cobol_parser-3.3.0-cp313-cp313-win_amd64.whl
Size 1.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
0b3a75e77ed1d21028b06e4a01d36326a4fba90e6f86c8ad13532a279b346103
BLAKE2b-256 checksum
How to use checksums
8ec24c631fc8849797bd158e6c02e989c374ad5280600d16a0fe58578faad958
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.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cobol_parser-3.3.0-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
f5f25813b99a7c3831009c578734dc8686c0b29913f3220e64b0149ac0aeea3d
BLAKE2b-256 checksum
How to use checksums
62c5157fa3039983fb713c5cc2958235c95355e14d63e11c2fc626bc0383d5ca
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.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL cobol_parser-3.3.0-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
fcaa6cf905ce88bc9a09ad235df5d7abb5d1870f4f275219a9b547bf2eb57cca
BLAKE2b-256 checksum
How to use checksums
67da7903e90c4c4f7e56fa395b995cf90295a3fc11ffd9522b1945d01067ac5e
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.0-cp312-cp312-win_amd64.whl

Download URL cobol_parser-3.3.0-cp312-cp312-win_amd64.whl
Size 1.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
c9edaa3854253df1906dadf809cc25857fd8d195dddf09c5203f79a8a52d4598
BLAKE2b-256 checksum
How to use checksums
f51d3c8289b737fd4cc8d24d6f1e08c6c24b1ef8d151479a15f508ea86d91c93
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.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cobol_parser-3.3.0-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
d6883dfa7a41c0726beca37423d3442c09332990e7d1be6f9a2585a7d5defc8c
BLAKE2b-256 checksum
How to use checksums
9d7af400b3052d13134e1675d1b5cdd5e5d241497014cf581e401ca07796b1b6
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.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL cobol_parser-3.3.0-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
a60457602c79922b9bcbf303998ff71b0a4ee0ba7f0fe13794b932ddb81e6a65
BLAKE2b-256 checksum
How to use checksums
d49110ac54310e4ea5c3498aa56ccccc35b37a2306177dec82c33a9754bfc4df
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.0-cp311-cp311-win_amd64.whl

Download URL cobol_parser-3.3.0-cp311-cp311-win_amd64.whl
Size 1.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c0d5d5feabca9cbda0f06ff8cf709568c9227cda4b2b909a8ab4f40530b79903
BLAKE2b-256 checksum
How to use checksums
61df89ec5ab156c15e2b316d55bdd77dd4b3819721e0f88f1cec2f76b38b09ca
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.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL cobol_parser-3.3.0-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
f59750d27eac783338ba7268358744ed34f61ae72772182a03cf5574242378ba
BLAKE2b-256 checksum
How to use checksums
c9e1fca5d0953cd3daeeee78fc7eb683e54aafa589877bbcd85d1521968054a6
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.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL cobol_parser-3.3.0-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
ac13a8f465216f5d12d1734d004ac11538737c886168df7a57097892f5d1405a
BLAKE2b-256 checksum
How to use checksums
39797ad20d211e236a87e97450dec634299d6f0362d8c340c280c5bdb6446409
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.0

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