Skip to main content

DocDSL

Version License Status Open Source GitHub issues Last Commit

A declarative DSL for extracting structured information from OCR output, PDFs, reports, and other semi-structured documents.

Instead of writing large, difficult-to-maintain regular expressions, DocDSL lets you describe what to extract using a simple, readable language while keeping extraction rules separate from your application code.


Installation

pip install docdsl

Quick Start

from docdsl import DSLTranslator

translator = DSLTranslator()

dsl = """
FIND "Patient:";
SKIP UNTIL NEWLINE;
CAPTURE TARGET [@NAME];
"""

pattern = translator.translate(dsl)
print(pattern)

with open("doc.txt", "r") as fh:
    text = fh.read()
    matches = pattern.finditer(text)
    for matched in matches:
        print(f"{matched=}")
        matched_groups = matched.groupdict()
        name = matched_groups.get("NAME", None)
        print(f"Name: {name}")

The NAME entity is part of DocDSL's built-in entity library and is available automatically. Custom entities can still be supplied when additional matching behaviour is required.


Features

  • Declarative, English-like extraction language
  • Reusable named entities
  • Readable extraction rules
  • Conditional extraction using IF
  • Multi-line capture
  • Capture between delimiters
  • Built-in helper tokens
  • Friendly syntax and validation errors
  • Exact error locations with line and column information

Documentation

Complete language documentation is available in the DocDSL Documentation.

The reference includes:

  • Complete command reference
  • DSL syntax
  • Built-in helper tokens
  • Conditional statements
  • Examples
  • Best practices

Requirements

  • Python 3.11+

Contributing

Contributions, bug reports and feature requests are welcome.

If you discover a bug or have an idea for improving DocDSL, please open an issue or submit a pull request.


License

Released under the MIT License.

Release files for docdsl 0.0.3

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

Source distribution (sdist)

Source distribution for docdsl 0.0.3
File Size Uploaded
docdsl-0.0.3.tar.gz 15.7 kB Details

Built distribution (wheel)

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

Total release size: 34.4 kB

Release files / docdsl-0.0.3.tar.gz

Download URL docdsl-0.0.3.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7ea0bf35d17034e3d8cbc2f061947fa1890b1675abc28ddc49c3c50e37068dd2
BLAKE2b-256 checksum
How to use checksums
e9bb5f3e528a186538f320ae298f9af8e1dc288911229c5bf124afdfb9762535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / docdsl-0.0.3-py3-none-any.whl

Download URL docdsl-0.0.3-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
effc75330f8022b9514033bc4d0f3061bef41e41acba683ba1052b2bc72d880c
BLAKE2b-256 checksum
How to use checksums
27482530e4c7ac9e801b792987f8ff18f028772beb37f36eac85aa607bbf9704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

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