Skip to main content

Downloads

Copybook

Copybook is a python module for parsing VSAM copybooks.

Features

  • Supports all numeric PIC variations including:
    • integers
    • floats described with dot notation
    • floats described with V notation
    • leading SIGNED
    • trailing SIGNED
  • Character PIC notations
  • Groups
  • OCCURS clauses
  • REDEFINES clauses

In addition, it provides indexes of column locations to help with parsing fixed width files based on positions within each line

Installation

pip install copybook

Usage

Copybook provides two methods for parsing copybooks: parse_file and parse_string. The result is a FieldGroup object that represents the root of the copybook tree.

Examples:

import copybook
text = """
       01  WORK-BOOK.
        10  TAX-RATE        PIC S9(13)V9(2)
                    SIGN LEADING SEPARATE.
"""
root = copybook.parse_string(text)

Using Copybook module to parse a fixed width line

The FieldGroup object provides a flatten method that return a flat list of Field objects.

Example:

import copybook
text = """
       01  WORK-BOOK.
        10  TAX-RATE        PIC S9(13)V9(2)
                    SIGN LEADING SEPARATE.
        10  AMOUNT        PIC S9(4)V9(2).
"""
# copybook also provides a parse_file method that receives a text filename
root = copybook.parse_string(text)

# flatten returns a list of Fields and FieldGroups instead of traversing the tree
list_of_fields = root.flatten()

# dummy sample input
line = "          -13452987654"

# loop over the fields and parse the relevant position in the line
for field in list_of_fields:

  # FieldGroups are Copybook groups and contain Field objects as children
  if type(field)==copybook.Field:

    # each Field has a start_pos and a get_total_length method
    # to identify the position within the raw line input
    str_field = line[field.start_pos:field.start_pos+field.get_total_length()]

    # Field provides a parse method that returns a str, int, or float based on the PIC
    print(f"{field.name}: {field.parse(str_field)}")

Development

PRs are always welcome!

Support

If you encounter an unsupported copybook feature, please paste the copybook example along with whatever logs or error message you have received and open an issue.

Gratitude

Copybook uses the awesome PyParsing library for tokenization

License

MIT

Metadata

Release files for copybook 1.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for copybook 1.0.16
File Size Uploaded
copybook-1.0.16.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for copybook 1.0.16
File Interpreter ABI Platform
copybook-1.0.16-py3-none-any.whl Python 3 none any Details

Total release size: 14.7 kB

Release files / copybook-1.0.16.tar.gz

Download URL copybook-1.0.16.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a86ab10a9cebcff5f1de37ba35fa94eb2c1ed19d72b16e3424b40322f72fd10a
BLAKE2b-256 checksum
How to use checksums
6dbce1de3f0b0715ea86a3d95c144f84b87d7cad70a4854a42b4f679b5685051
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / copybook-1.0.16-py3-none-any.whl

Download URL copybook-1.0.16-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
35c085fb828a4fc25a9f2c3db3b82eda929764c9748f738b139b67d35afcba19
BLAKE2b-256 checksum
How to use checksums
d5c1a593f2fe9bf3fc408d5fae081c7a18052a602d8b07c2873f72ddc368eca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

1.0.16 This release

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.7

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.2

2 release files

1.0.1

2 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