Skip to main content

# flexible-data-parser

This module is designed to convert semi-structured text data into Python dicts (or lists) by interpreting an XML configuration file.

## Usage

from fdp import FileParser

p = FileParser(“/path/to/config.xml”) parsed_dict = p.parse(“/path/to/target.txt”)

## Theory

The parser walks through the target text file one line at a time, comparing the current line with the regexes defined in the config file. Matching capture groups are stored according to the specified keys in the config file.

The process supports loops (if there are multiple instances of a kind of data stored in a single file). For example, a text invoice might have several line items, each broken out into three lines; in the config file, you can define a Section for each line item, with a separate regex for each line of text.

## XML Configuration

A sample configuration file is included.

### Section

Defines how to populate a list or dict with data.

Attributes:

  • name - Key to store the list or dict under in above section

  • key - [Optional] If defined, this section will be a dict, and will use the value of the specified key from child dicts as the index

Contains:

  • <repeat-until> - [Optional] Text node; regex that signals the end of any further repeats of this section

  • <section> - [Optional] Defines how to populate a list or dict with data

  • <line> - [Optional] Defines how to match and capture data from a line of text

### Line

Defines how to match and capture data from a line of text

Attributes:

  • ignore - [Optional] Boolean; if true, wait for this line to appear in the file, but do not save any capture groups.

  • optional - [Optional] Boolean; if true, this line can be skipped if a match is found for the next line. (By default, no line can be skipped, and the parser will continue reading the target file until the next matching line is found.)

Contains:

  • <regex> - Specifies the regex the line must match. Any capture groups will be saved.

  • <fields> - Contains <field> elements * <field> - Specifies the key in which to store the data from the capture group(s). Must be a number of <field> elements equal to the number of capture groups.

Metadata

Release files for flexible-data-parser 1.0

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

Built distribution (wheel)

Table of built distributions (wheels) for flexible-data-parser 1.0
File Interpreter ABI Platform Actions
flexible_data_parser-1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for flexible_data_parser-1.0-py2.py3-none-any.whl

Release files / flexible_data_parser-1.0-py2.py3-none-any.whl

Download URL flexible_data_parser-1.0-py2.py3-none-any.whl
Size 6.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
db1ece87c3af03457ff22c8689fa8caff78c1c7cbcdce02922f3953eecd83391
BLAKE2b-256 checksum
How to use checksums
0f5be37a977a82d290d98a5ed1e96c4d0606fa0cb9b20b246e172d5473f06785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for flexible-data-parser 1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file No provenance

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