Skip to main content

Deckard 🕵️‍♂️

Extract structured data from unstructured text — no AI, just regular expressions. 🔍

GitHub License Tests Codecov PyPI - Python Version PyPI - Version Code style: black Linting: Ruff Pytest

Deckard is a library of regular-expression patterns for extracting structured data (addresses, phone numbers, email addresses, etc.) and a small set of helper utilities that make using those patterns easier.

Status: very early-stage project. Right now the repository contains mostly patterns for Poland. I am looking for contributors from around the world 🌍 — address formats, phone-number formats and other data representations differ by country, so the goal is to gather country-specific patterns for many regions.

Key features ✨

Installation ⚙️

From PyPI:

pip install deckard

Editable / local development install:

pip install -e .

For contributors — install dependencies with Poetry 🧑‍💻

This project uses Poetry to manage dependencies and development dependencies.

  1. Install Poetry (see https://python-poetry.org for instructions).
  2. From the project root run:
poetry install

This will create a virtual environment and install runtime and development dependencies (including pytest).

To run tests using Poetry:

poetry run pytest

Or start a shell in the created virtualenv and run tests directly:

poetry shell
pytest

Quick usage 🧭

Example using the current public API:

from deckard import search
from deckard.patterns import standard, pl

text = (
    "Hello, my email is spaceshaman@tuta.io and my phone number is "
    "+48 792 321 321 and my address is ul. Tesotowa 12/6A, 66-700 Bielsko-Biała."
)

result = search([standard.EMAIL, pl.MOBILE_PHONE, pl.ADDRESS], text)

# result.groupdict() will return a dict of named groups, for example:
# {
#   'email': 'spaceshaman@tuta.io',
#   'mobile_phone': '792 321 321',
#   'street': 'ul. Tesotowa',
#   'building': '12',
#   'apartment': '6A',
#   'zip_code': '66-700',
#   'city': 'Bielsko-Biała'
# }

The search helper composes the provided patterns into a single regex (using lookaheads) and returns the first match as a regex.Match object (or None if nothing matched).

Repository layout

Examples of existing tests:

Every new pattern must come with tests. Pull requests without tests will not be accepted.

Contributing — how to add new patterns

  1. Create a new file under deckard/patterns/ named by the country code, e.g. us.py, de.py, fr.py.
  2. Define constants (UPPERCASE) for each pattern, for example MOBILE_PHONE, ADDRESS, ZIP_CODE.
  3. Add tests under tests/. Use the existing Polish tests (e.g. tests/test_search_with_multiple_patterns.py) as a template. Provide normal and edge-case examples.
  4. In the PR description explain local rules (phone number format, postal code format, common street abbreviations, etc.).
  5. PRs without tests will not be accepted.

Tips 💡:

  • 🧾 Use clear, consistent named groups in regexes (?P<name>) so groupdict() returns a predictable structure.
  • 📝 Document complex patterns with comments and example inputs if necessary.

Discussion and roadmap 🚧

The project is not yet final — everything is open for discussion. Areas for contributors and discussion include:

  • 📋 Defining a minimal set of patterns every country should provide (email, phone, address, postal code, national ID where applicable).
  • 🔠 Standardizing group names (street, building, apartment, zip_code, city, country, mobile_phone, etc.).
  • ⚖️ Tools for validation and normalization of extracted values.
  • 🤖 Automating tests with sample documents in various languages.

If you want to help, open an issue or a PR — a short description of the local data format and one or two patterns with tests is a great place to start.

License 📄

This project is licensed under the MIT License. See the LICENSE file for the full text.


Thanks for your interest — please join the effort. Together we can build an international library of patterns to extract structured data from arbitrary text using robust regular expressions. 🚀

Metadata

Release files for deckard 0.1.0

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

Source distribution (sdist)

Source distribution for deckard 0.1.0
File Size Uploaded Provenance
deckard-0.1.0.tar.gz 4.8 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 10.8 kB

Release files / deckard-0.1.0.tar.gz

Download URL deckard-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7fdcbac0ae6eef71123efe0efffed065ab66c471699bcf86f6195afbf7ea8d32
BLAKE2b-256 checksum
How to use checksums
ff1553003d36fd8d2d79ba0f29bdb751a8bf76e2f54dfcf6ba10e658bbbf9aae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.11 Linux/6.8.0-1031-azure

Release files / deckard-0.1.0-py3-none-any.whl

Download URL deckard-0.1.0-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7e616f7507dbedad0787cf21b291c3efc747f3dd24ad1bbc820bdbab4e369ee
BLAKE2b-256 checksum
How to use checksums
8bb790e19c1738af0768c86254731c304ebe20446b40ed137f471038e5f2a413
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.11 Linux/6.8.0-1031-azure

Security for deckard 0.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

0.1.0 This release

2 release files 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