Skip to main content

Docling PDF conversion package

Project description

Docling

Docling

PyPI version Python Poetry Code style: black Imports: isort Pydantic v2 pre-commit License MIT

Docling bundles PDF document conversion to JSON and Markdown in an easy, self-contained package.

Features

  • ⚡ Converts any PDF document to JSON or Markdown format, stable and lightning fast
  • 📑 Understands detailed page layout, reading order and recovers table structures
  • 📝 Extracts metadata from the document, such as title, authors, references and language
  • 🔍 Optionally applies OCR (use with scanned PDFs)

Installation

To use Docling, simply install docling from your package manager, e.g. pip:

pip install docling

[!NOTE] Works on macOS and Linux environments. Windows platforms are currently not tested.

Development setup

To develop for Docling, you need Python 3.10 / 3.11 / 3.12 and Poetry. You can then install from your local clone's root dir:

poetry install --all-extras

Usage

Convert a single document

To convert invidual PDF documents, use convert_single(), for example:

from docling.document_converter import DocumentConverter

source = "https://arxiv.org/pdf/2206.01062"  # PDF path or URL
converter = DocumentConverter()
doc = converter.convert_single(source)
print(doc.export_to_markdown())  # output: "## DocLayNet: A Large Human-Annotated Dataset for Document-Layout Analysis [...]"

Convert a batch of documents

For an example of converting multiple documents, see convert.py.

From a local repo clone, you can run it with:

python examples/convert.py

The output of the above command will be written to ./scratch.

Adjust pipeline features

Control pipeline options

You can control if table structure recognition or OCR should be performed by arguments passed to DocumentConverter:

doc_converter = DocumentConverter(
    artifacts_path=artifacts_path,
    pipeline_options=PipelineOptions(
        do_table_structure=False,  # controls if table structure is recovered
        do_ocr=True,  # controls if OCR is applied (ignores programmatic content)
    ),
)

Control table extraction options

You can control if table structure recognition should map the recognized structure back to PDF cells (default) or use text cells from the structure prediction itself. This can improve output quality if you find that multiple columns in extracted tables are erroneously merged into one.

pipeline_options = PipelineOptions(do_table_structure=True)
pipeline_options.table_structure_options.do_cell_matching = False  # uses text cells predicted from table structure model

doc_converter = DocumentConverter(
    artifacts_path=artifacts_path,
    pipeline_options=pipeline_options,
)

Impose limits on the document size

You can limit the file size and number of pages which should be allowed to process per document:

conv_input = DocumentConversionInput.from_paths(
    paths=[Path("./test/data/2206.01062.pdf")],
    limits=DocumentLimits(max_num_pages=100, max_file_size=20971520)
)

Convert from binary PDF streams

You can convert PDFs from a binary stream instead of from the filesystem as follows:

buf = BytesIO(your_binary_stream)
docs = [DocumentStream(filename="my_doc.pdf", stream=buf)]
conv_input = DocumentConversionInput.from_streams(docs)
converted_docs = doc_converter.convert(conv_input)

Limit resource usage

You can limit the CPU threads used by Docling by setting the environment variable OMP_NUM_THREADS accordingly. The default setting is using 4 CPU threads.

Contributing

Please read Contributing to Docling for details.

References

If you use Docling in your projects, please consider citing the following:

@software{Docling,
author = {Deep Search Team},
month = {7},
title = {{Docling}},
url = {https://github.com/DS4SD/docling},
version = {main},
year = {2024}
}

License

The Docling codebase is under MIT license. For individual model usage, please refer to the model licenses found in the original packages.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docling-1.1.1.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

docling-1.1.1-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file docling-1.1.1.tar.gz.

File metadata

  • Download URL: docling-1.1.1.tar.gz
  • Upload date:
  • Size: 30.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1024-azure

File hashes

Hashes for docling-1.1.1.tar.gz
Algorithm Hash digest
SHA256 f24e828569bc34cac942eebce8c11dc4a31bfcc6cedfb50c9f009b9cf619ded1
MD5 c9bdd5a2145aa49a689d2cab64d6bdef
BLAKE2b-256 1113c4cf8adf583adae89b2b7f8740e35456957a295419929b48cf99834e0c9f

See more details on using hashes here.

Provenance

File details

Details for the file docling-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: docling-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1024-azure

File hashes

Hashes for docling-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30fef31e97e9ebc3a7a631713bf89ebec911b0763141070bf6efe5c15c1ae665
MD5 b146010f03119cf9af801851f7566ff5
BLAKE2b-256 d33980a0e9e023de0ac28cad8a9c9441b69c30b98a7e04a06146fd826c518ec9

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page