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

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

Built distributions (wheels)

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

Total release size: 19.4 MB

Release files / cobol_parser-3.3.2.tar.gz

Download URL cobol_parser-3.3.2.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
0e6d4e1b811293d5f965bc879f6a4e052b5b3ec8d5cf8ab633291d10acb335a5
BLAKE2b-256 checksum
How to use checksums
a2135e5fcd241443c3e276b1894f0f3564f0cb51f54abcf3f83ba3c04603f901
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-cp313-cp313-win_amd64.whl
Size 1.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
9dbb089367aa1c2ad2fbcbc0ec30da8c178dadf71e921987a5598765adf431b1
BLAKE2b-256 checksum
How to use checksums
5d659492e7a8f24e6fffbb12fb994b6aeabbc99c77e7fcd395c409e0f8c82e86
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-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
651873dd4c60432d0517e5b2721b0b997d437f1190d17f1cdb587e9616aa0344
BLAKE2b-256 checksum
How to use checksums
492afdcf36c8f3376870dd84808f4a37574baf4217914db7bedf9769c81f9c49
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-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
7b262b2351b1ff9078e8727bc6176b519949ff9b67c2263d3306b0c0c815e35b
BLAKE2b-256 checksum
How to use checksums
866fa8385d64bc110e1887b57d782f4923fbe97e7798f37383fcf5ef094345c9
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-cp312-cp312-win_amd64.whl
Size 1.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
9fa674dc6d5479c56b68eaf3071c5fd382438a7a504f07ba40bd6ce0b49f9af6
BLAKE2b-256 checksum
How to use checksums
301a8e6d72ebaeedbc9d44543faabb50196f92f0c88cb99c35d2d8ff0c4ebbc2
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-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
8aac6f7aa4972e5c7d2aeb2dfe30c2a5b8e96d87d526afff29fb59ac66ef4269
BLAKE2b-256 checksum
How to use checksums
74a7fa4acfb8249624c485e5931e8befceb4c218c813f355a6b46e2efed3ee6b
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-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
6ec0c0d193b262cbd5de0899e57eb4e856c8185e7bee35f273c1a0e26448d861
BLAKE2b-256 checksum
How to use checksums
e191b68d2d9f480f8c1fef4f87d07b91e22b987e605f31415b29537851950f53
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-cp311-cp311-win_amd64.whl
Size 1.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
652baee9d51621488e018c59e5dc71c466388b93fc0ac31ec547c54611d7f42e
BLAKE2b-256 checksum
How to use checksums
297dfcc2d11d23eeb32bfbf1593834ca9e31512542d23cf0553f466cf7404f71
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-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
90431d114c6d6ef07169f4ee264eddfb76982d44be52530b51b2d4878dfd4e6b
BLAKE2b-256 checksum
How to use checksums
13dec3b1bbeefa8cf80ee909d262bb9a4be8218fdd2978fa2e742ee2682e97b2
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 3, 2026.

Transparency log

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

Download URL cobol_parser-3.3.2-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
c73616d1e4a2460dbaf5c28574bca70e6bcc4ce6681a9c2490637729bfbfd972
BLAKE2b-256 checksum
How to use checksums
80497920f403c529e3eac33c9268fbbc60f40f38f89e0ff8eaab2d0178ec3414
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 3, 2026.

Transparency log

Security for cobol-parser 3.3.2

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.2.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 3, 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