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, Entity

# Define reusable entities
NAME = Entity(
    name="NAME",
    pattern=r"[A-Za-z ,.'-]+"
)

POSTCODE = Entity(
    name="POSTCODE",
    pattern=r"[A-Z]{1,2}\d[A-Z\d]?\s?\d[A-Z]{2}"
)

# Create the translator
translator = DSLTranslator(
    entities=[
        NAME,
        POSTCODE,
    ]
)

# Describe what to extract
dsl = """
FIND "Name:";
SKIP UNTIL NEWLINE;
CAPTURE TARGET [@NAME];
"""

# Generate the regular expression
pattern = translator.translate(dsl)

print(pattern)

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

For the complete language reference, see DSL_REFERENCE.md.

The reference includes:

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

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.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 docdsl 0.0.2
File Size Uploaded
docdsl-0.0.2.tar.gz 13.8 kB Details

Built distribution (wheel)

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

Total release size: 29.9 kB

Release files / docdsl-0.0.2.tar.gz

Download URL docdsl-0.0.2.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e7448c15db80c618836544884bf14666aaa0f2844f355891afab5d0611f44848
BLAKE2b-256 checksum
How to use checksums
4243a40d79d7b677fad444e4174df6ad3d7fedef0dae6fc133ceb4ed4e1f8b71
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.2-py3-none-any.whl

Download URL docdsl-0.0.2-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29f740bc98560a1dd2c4f06d1fa37cda66b8deeded681e5eec7e1a271690ed28
BLAKE2b-256 checksum
How to use checksums
16e27ab268e5fd8a63c6e29cb08d5e7f7a7f0fe92e9a28c53b19b046be24f0d5
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

0.0.3

2 release files

This release

0.0.2 This release

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