DocDSL
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
1. Define your entities
Entities are reusable regular expressions that can be referenced throughout your DSL.
from docdsl import DSLTranslator, Entity
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}"
)
2. Create a translator
translator = DSLTranslator(
entities=[
NAME,
POSTCODE,
]
)
3. Write your extraction rules
dsl = """
FIND "Name:";
SKIP UNTIL NEWLINE;
CAPTURE TARGET [@NAME];
"""
4. Generate the regular expression
pattern = translator.translate(dsl)
Your DSL is translated into a regular expression that can be used as part of your document extraction pipeline.
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
Entities
Entities represent reusable regular expressions.
TITLE = Entity(
name="TITLE",
pattern=r"(?:Mr|Mrs|Ms|Miss|Dr)\.?"
)
Supply your entities when creating the translator.
translator = DSLTranslator(
entities=[
TITLE,
NAME,
POSTCODE,
]
)
Inside the DSL, entities are referenced using the @ prefix.
@TITLE
@NAME
@POSTCODE
If the DSL references an entity that was not supplied to DSLTranslator, an UndefinedEntity exception is raised.
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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| docdsl-0.0.1.tar.gz | 14.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| docdsl-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.5 kB
Release files / docdsl-0.0.1.tar.gz
| Download URL | docdsl-0.0.1.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31529cb7d9157db02f3a1209c56e5f81ce5254180451375b665af05e55d0ebe8
|
|
BLAKE2b-256 checksum How to use checksums |
7629f63e544404df09722858549b95a457e22a1fb46b513bb55b5a596127deec
|
| 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.1-py3-none-any.whl
| Download URL | docdsl-0.0.1-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c749d920319c1768eca5fd971d456b353dada6d14f5b706b40c9e7156c738aa5
|
|
BLAKE2b-256 checksum How to use checksums |
c8ad5e3a2aef078c1026030c95c23eb12e0c07237368a4edc715f80516a33d47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|