Skip to main content
grobid-tei logo

grobid-tei

PyPI - Version PyPI - Python Version License GitHub Actions

grobid-tei is a reusable Python client for an independently managed GROBID service and a parser for its TEI XML output. It supports Python 3.10 and newer. It does not start Docker or manage the GROBID service lifecycle.

Installation

pip install grobid-tei

For a local checkout, install the package and its test tools with uv:

uv pip install .
uv sync --extra test

Pre-commit checks

Install pre-commit and enable the repository hooks:

uv tool install pre-commit
pre-commit install
pre-commit run --all-files

The hooks check common file issues, format with Black, lint with Ruff, ensure Python 3.10-compatible syntax, and run the test suite. The copied TEI XML fixture is excluded from whitespace-fixing hooks so its source representation is preserved.

Convert a PDF to TEI

Start or otherwise provide a GROBID service yourself, then configure its full base URL explicitly:

from pathlib import Path

from grobid_tei import GrobidClient, TEIDocument

client = GrobidClient(service_url="http://localhost:8070", timeout=180)
if not client.is_available():
    raise RuntimeError("GROBID is not available")

tei_xml = client.process_fulltext(Path("paper.pdf"))
Path("paper.tei.xml").write_bytes(tei_xml)

document = TEIDocument.from_bytes(tei_xml)
print(document.metadata())
print(document.metadata(abstract=True))
print(document.abstract())
print(document.references(include_citation_counts=True))

process_fulltext returns XML bytes. To enable GROBID consolidation explicitly, pass consolidate_header=True and/or consolidate_citations=True.

Parse an existing TEI file

No running GROBID service is needed to parse an existing file:

from pathlib import Path

from grobid_tei import TEIDocument

document = TEIDocument.from_file(Path("paper.tei.xml"))
print(document.grobid_version())
print(document.keywords())
print(document.author_details())

for paragraph in document.iter_paragraphs():
    print(paragraph)

Public API

  • GrobidClient(service_url=..., timeout=180.0) provides is_available(), version(), optional check_compatibility(), and process_fulltext(...). The compatibility check rejects known-incompatible versions and warns, but proceeds, for versions not yet tested with this package. It is not run automatically during processing. IncompatibleGrobidVersionError identifies a known-incompatible server version.
  • TEIDocument.from_bytes(...) and TEIDocument.from_file(...) create a parsed document. It provides to_bytes(), grobid_version(), metadata(), abstract(), keywords(), author_details(), references(), citations_by_section(), iter_paragraphs(), and annotate_reference_ids(...).
  • TEIReference is a mapping of generic lowercase bibliographic fields (title, author, year, doi, journal, and similar), with the GROBID identifier in .tei_id and an optional citation count in .in_text_citation_count. The identifiers and count are not included in its bibliographic field mapping.
  • GrobidServiceError describes service request failures; TEIParsingError describes unsafe or invalid TEI XML. Both inherit from GrobidTEIError.

The parser uses defusedxml for safe XML parsing. annotate_reference_ids() applies only a caller-supplied mapping from TEI IDs to caller IDs; it performs no reference matching or workflow decisions.

License

This project is licensed under the MIT License.

Metadata

Release files for grobid-tei 0.2.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 grobid-tei 0.2.0
File Size Uploaded Provenance Actions
grobid_tei-0.2.0.tar.gz 748.6 kB With provenance Details for grobid_tei-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grobid-tei 0.2.0
File Interpreter ABI Platform Actions
grobid_tei-0.2.0-py3-none-any.whl Python 3 none any Details for grobid_tei-0.2.0-py3-none-any.whl

Total release size: 759.5 kB

Release files / grobid_tei-0.2.0.tar.gz

Download URL grobid_tei-0.2.0.tar.gz
Size 748.6 kB
Tags Source
SHA-256 checksum
How to use checksums
49a1d0aeb1673b48b77e06961dc3c38535aa743e88166b21d9b2637ca5f0399c
BLAKE2b-256 checksum
How to use checksums
065b4285fa2a3577a4687662ca1a6f27c49e1e57519ef230d194bde22f73ed6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Release files / grobid_tei-0.2.0-py3-none-any.whl

Download URL grobid_tei-0.2.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f655c44a24b6be15d8413c00c3ba2a5b12ad8b18d74ad0998d324af1ee6a054a
BLAKE2b-256 checksum
How to use checksums
901f9a39d379e51b3809d09932855b97becd9b5f6c26d3fab1f5391dd7e757c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

Security for grobid-tei 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for grobid_tei-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.

Transparency log

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.

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