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 is currently switched off (.github/workflows/ci.yml is commented out), 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.2.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.2.1
File Size Uploaded Provenance Actions
cobol_parser-3.2.1.tar.gz 1.7 MB With provenance Details for cobol_parser-3.2.1.tar.gz

Built distributions (wheels)

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

Total release size: 19.0 MB

Release files / cobol_parser-3.2.1.tar.gz

Download URL cobol_parser-3.2.1.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
3d078a5e805667d22663c687b0c1e7df390fb15dc659c261dc50d912f4f51ea6
BLAKE2b-256 checksum
How to use checksums
4a98b074238b617f1c24c3d1bab2876258cd637d7a6504da4cce2d0fe0379ec7
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.1-cp313-cp313-win_amd64.whl
Size 1.6 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
c2f669e7f64b59dbe682708569bba6afec54fb5e29f1ade4814421055a960feb
BLAKE2b-256 checksum
How to use checksums
501b27fd6dd1e11d0a323ce8fe7e1bbfa2dc19ca1b934f34a4f09ccf8b909732
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.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
b9169724220b25e6f9b888722f5ab43605d431d94c694b7056d70928f7e650e1
BLAKE2b-256 checksum
How to use checksums
782cde86bb1ec1abaf2a9196bcd138bdeb586069b31a6c8afa01569b94b8c44c
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.1-cp313-cp313-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5e1e0a9672d3dbfaef8946d18d99e454b66458db90a741344c3171f18c3df413
BLAKE2b-256 checksum
How to use checksums
3d8e591c2f608757b2dae4f5f2eae3eb175e5d952a49a31cb51257f64fb661dc
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.1-cp312-cp312-win_amd64.whl
Size 1.6 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
a40b397b6cf98863a1cea7e89d03202edfacc81b27cbf900be12f5a013a46226
BLAKE2b-256 checksum
How to use checksums
8060e46f64c1b0e28ab88ca8cd28205fe20fc5c069647b9d7e88213aee20a0a5
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.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
ff288f7ea88a5bbec4b8550d15bf8cc1cb9b7e87050f98d612c05e07902c0034
BLAKE2b-256 checksum
How to use checksums
16afb45c9a3324a0b144e8afa8a5fcbd95e36b5f0ca8c52b2d282675be7f0dab
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.1-cp312-cp312-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ca55f5e6d1bc0a9c518c40367da592b4fea6fc6f3345212bbf11a38fa3d8c879
BLAKE2b-256 checksum
How to use checksums
eec9f8e582849c9a531912253e5826d4cdebde15366581efa48c5c72f9905161
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.1-cp311-cp311-win_amd64.whl
Size 1.6 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ef6f600e0656991a26a4b6c764c32f09a570371ccceb90d98b84b934283c4879
BLAKE2b-256 checksum
How to use checksums
b777de4bef845744552b7af51d098b44febc56505aca7b7924f2b0d5d4cef1e1
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.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
67bf7698c703b70464560a8f90de0444c43d17f4c6ec252ecd5c4f21dc1994ff
BLAKE2b-256 checksum
How to use checksums
d842018b5a6f035805859ec6e75f7b89c04c4fa63aacff1c6ad88461d5be91bf
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 30, 2026.

Transparency log

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

Download URL cobol_parser-3.2.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
f332c2ac336841bbae5d6495b6086e2931a420470e0a63295ce69ae5454ce034
BLAKE2b-256 checksum
How to use checksums
3a580ed521de772a94d90c52607881533f81f14ed9155016f990d093cea9ec44
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 30, 2026.

Transparency log

Security for cobol-parser 3.2.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.2.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 30, 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