gdelt-regkg
Package for reconstructing GDELT GKG files from article text and metadata.
gdelt-regkg converts prepared article bodies and supplied metadata into GKG records. It can be used for reconstructing gaps in GKG coverage, processing your own news datasets, or extract individual fields for analysis. To make it work you just need article text and some metadata, while the library extracts and formats the fields automatically. You can generate full GKG entry or extract data only for specific fields.
The row structure, metadata formatting and field encodings are documented in GDELT Global Knowledge Graph Codebook. Extraction from text approximates GDELT's processing, so themes, counts, entities, tone and other inferred values can differ from native GKG results.
See the field documentation and measured agreement, resource and benchmark tools, and changelog.
Installation
Requires Python 3.12 or newer. Install the library and its English model, then prepare the extraction dictionaries:
python -m pip install "gdelt-regkg[ner]"
python -m spacy download en_core_web_sm
gdelt-regkg-cli build all --sources-dir downloads/resources --download-sources --output local-resources
Installation covers package dependencies and model setup. See API usage for Python examples and Build resources for dictionary profiles and source files.
Usage
Extract individual fields
Import structured analyzers from their field modules. Serialize the result when a GKG cell is needed:
from gdelt_regkg.fields.counts import analyze_counts
from gdelt_regkg.fields.themes import analyze_themes
from gdelt_regkg.fields.tone import analyze_tone
text = "Flooding killed 12 people."
counts = analyze_counts(text)
print(counts.to_gkg())
print(counts.to_gkg(enhanced=True))
print(analyze_themes(text).to_gkg())
print(analyze_tone(text).to_gkg())
CRISISLEX_T03_DEAD#12#people#0######;KILL#12#people#0######;
CRISISLEX_T03_DEAD#12#people#0#######16;KILL#12#people#0#######16;
CRISISLEX_C06_WATER_SANITATION;NATURAL_DISASTER_FLOODING;CRISISLEX_T03_DEAD;KILL;
-25,0,25,25,25,0,4
Tone, themes, geographic references and GCAM need prepared local profiles. Counts and name rules are included. Default profiles are cached by resolved path; reuse explicit objects or reload them after edits. For pandas, use df["themes"] = df["text"].map(lambda text: analyze_themes(text).to_gkg()); install pandas separately and normalize missing values.
Generate a GKG record
from gdelt_regkg import RecordMetadata, Resources, generate_gkg, write_gkg
from gdelt_regkg.fields.ner import SpacyNER
text = "Flooding killed 12 people in London."
metadata = RecordMetadata(
identifier="https://example.org/story",
batch_time="20261001091500",
sequence=1,
sharing_image="",
related_images=[],
social_image_embeds=[],
social_video_embeds=[],
extras={},
)
resources = Resources(resources_dir="local-resources", recognizer=SpacyNER.from_model())
record = generate_gkg(text, metadata, resources, strict=True)
with open("articles.gkg.tsv", "w", encoding="utf-8", newline="") as stream:
write_gkg([record], stream)
The frozen GKGRecord has 27 typed attributes, native column-name mapping access, to_mapping() and to_row(). An empty cell means no matches; None means unavailable metadata or model-dependent work. strict=True raises IncompleteGKGError; otherwise unavailable fields produce IncompleteGKGWarning. Export them explicitly with allow_incomplete=True.
Translate non-English bodies first and use RecordMetadata.from_translation(result, metadata). Enhanced offsets refer to result.text. See API usage for translation, batching, caching, overrides and resource composition, and the Unreleased migration guide for breaking API changes.
Supported fields
All 27 GKG wire columns are supported. Text-derived fields approximate GDELT processing; metadata and media fields format values supplied by the caller. Enhanced fields add offsets into the analyzed English body. Follow the field links for formats, examples and limitations.
| GKG column | How it is produced | Setup |
|---|---|---|
| GKGRECORDID | Batch timestamp and sequence; T marks translated records |
Supplied RecordMetadata |
| V2.1DATE | Batch timestamp; publication time is kept separately in extra XML | Supplied metadata |
| V2SOURCECOLLECTIONIDENTIFIER | Validated source collection identifier | Supplied metadata |
| V2SOURCECOMMONNAME | Supplied source name or hostname derived from the document URL | Supplied metadata |
| V2DOCUMENTIDENTIFIER | Supplied document URL or identifier | Supplied metadata |
| V1COUNTS | Authored English number/event rules with optional resolved geography | Rules included; NER and geography for place enrichment |
| V2.1COUNTS | Count matches with character offsets | Same as counts |
| V1THEMES | Phrase matching against theme dictionaries | Build local resources |
| V2ENHANCEDTHEMES | Theme matches with offsets | Same as themes |
| V1LOCATIONS | NER place mentions resolved against an offline gazetteer | spaCy model and local resources |
| V2ENHANCEDLOCATIONS | Resolved place occurrences with offsets and administrative details | Same as locations |
| V1PERSONS | NER person mentions with name normalization and filtering | NER extra and English model |
| V2ENHANCEDPERSONS | Person mentions with offsets | Same as persons |
| V1ORGANIZATIONS | NER organization mentions with authored name filtering | NER extra and English model |
| V2ENHANCEDORGANIZATIONS | Organization mentions with offsets | Same as organizations |
| V1.5TONE | Dictionary-based tone, polarity, activity, self-reference and word counts | Build tone resources |
| V2.1ENHANCEDDATES | English calendar/date patterns with offsets | Core only |
| V2GCAM | Matches across configured affect dictionaries | Build GCAM resources |
| V2.1SHARINGIMAGE | Formats the supplied sharing-image URL | Supplied metadata |
| V2.1RELATEDIMAGES | Formats supplied related-image URLs | Supplied metadata |
| V2.1SOCIALIMAGEEMBEDS | Formats supplied social-image embed URLs | Supplied metadata |
| V2.1SOCIALVIDEOEMBEDS | Formats supplied social-video embed URLs | Supplied metadata |
| V2.1QUOTATIONS | Quoted-span detection with offsets and lengths | Core only |
| V2.1ALLNAMES | Broader NER name labels with authored filtering and offsets | NER extra and English model |
| V2.1AMOUNTS | Number, currency and unit patterns with offsets | Core only |
| V2.1TRANSLATIONINFO | Formats language/engine provenance from explicit translation or metadata | Detection and translation setup for automatic provenance |
| V2EXTRASXML | Escapes and serializes supplied extra metadata as XML | Supplied metadata |
Language detection can also be used independently of GKG generation. See detect and translate an unknown language and CUDA/CuPy setup.
Contributing
Use the GitHub issue forms to report bugs, extraction differences or feature requests. Contributing describes local checks, pull requests and evaluation on data separate from rule development. Please follow the code of conduct. Report vulnerabilities privately as described in the security policy.
Benchmark
Use gdelt-regkg-cli benchmark to compare native and reconstructed GKG fields
and write Markdown and CSV metric tables. The benchmark guide
covers installation, input files and directories, field selection and metrics.
Disclaimer
This is an independent implementation, unaffiliated with and not endorsed by the GDELT Project. It produces approximate GKG fields, not guaranteed copies of GDELT's outputs. Results depend on article text, translation, models and dictionaries; validate them for your intended analysis. Differences from native GKG can also reflect different input bodies.
The code and original rules use the MIT license and are provided without warranty. MIT does not grant rights to external dictionaries, models, article bodies or generated profiles derived from them; their source terms still apply.
Metadata
Release files for gdelt-regkg 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gdelt_regkg-2.0.0.tar.gz | 474.3 kB | With provenance | Details for gdelt_regkg-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gdelt_regkg-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for gdelt_regkg-2.0.0-py3-none-any.whl |
Total release size: 862.2 kB
Release files / gdelt_regkg-2.0.0.tar.gz
| Download URL | gdelt_regkg-2.0.0.tar.gz |
|---|---|
| Size | 474.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d68a463afda8807a771be12aa670d124b80a14395db0492c9d639f0cb581936d
|
|
BLAKE2b-256 checksum How to use checksums |
d78ab8c0302e8e3ea9fecb758994773d17ae1176bd628695af18fdb2aaef4128
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 14, 2026.
Transparency logRelease files / gdelt_regkg-2.0.0-py3-none-any.whl
| Download URL | gdelt_regkg-2.0.0-py3-none-any.whl |
|---|---|
| Size | 387.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
54af2fc961693fe880ee7904271db3cf70a73a8fecbb2e2b20315b9241777937
|
|
BLAKE2b-256 checksum How to use checksums |
9ad1d1c165ca7ba1c7e48d16447c098f851b51fa336f41d490a1d9afaea24646
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 14, 2026.
Transparency logSecurity for gdelt-regkg 2.0.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.
Attestation for gdelt_regkg-2.0.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 Oct 14, 2026.
Transparency logA 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.