Skip to main content

gdelt-regkg

CI PyPI Python License DOI

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
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

Each field has a standalone function, so you do not need to generate a full GKG row.

from gdelt_regkg.fields import extract_counts, extract_themes, extract_tone

text = "Flooding killed 12 people and displaced 300 residents."

counts = extract_counts(text)
# CRISISLEX_T03_DEAD#12#people#0######;KILL#12#people#0######;AFFECT#300#residents#0######;CRISISLEX_CRISISLEXREC#300#residents#0######;CRISISLEX_T09_DISPLACEDRELOCATEDEVACUATED#300#residents#0######;DISPLACED#300#residents#0######;
themes = extract_themes(text)
# CRISISLEX_C06_WATER_SANITATION;NATURAL_DISASTER_FLOODING;CRISISLEX_T03_DEAD;KILL;AFFECT;CRISISLEX_CRISISLEXREC;CRISISLEX_T09_DISPLACEDRELOCATEDEVACUATED;DISPLACED;MANMADE_DISASTER_IMPLIED;
tone = extract_tone(text)
# -12.5,0,12.5,12.5,12.5,0,8

Functions return GKG-formatted cell strings and work with pandas, for example df["themes"] = df["text"].map(extract_themes). pandas package is optional and must be installed separately.

Tone, themes, geographic references and GCAM require locally prepared profiles. The default directory is local-resources/; select another with resources_dir= in Python or --resources-dir in the CLI. Explicit resource objects override directory defaults. Counts and name rules are available directly from the package.

Generate and save a row

from gdelt_regkg import SpacyNER, generate_gkg, write_gkg

ner = SpacyNER.from_model("en_core_web_sm", name_policy="surface")  # Load once and reuse.

record = generate_gkg(
    "Volunteers rescued 12 people in Paris, France.",
    identifier="https://example.org/story",
    published_at="20261001090023",  # Known precise publication time, stored in extra XML.
    batch_time="20261001091500",
    sequence=1,
    ner=ner,
    resources_dir="local-resources",
    sharing_image="",
    related_images=[],
    social_image_embeds=[],
    social_video_embeds=[],
    extras={},
    strict=True,
)

with open("example.gkg.csv", "w", encoding="utf-8", newline="") as stream:
    write_gkg([record], stream)

for column in ("V1COUNTS", "V1LOCATIONS", "V2.1AMOUNTS"):
    print(f"{column}: {record[column]}")
V1COUNTS: CRISISLEX_T08_MISSINGFOUNDTRAPPEDPEOPLE#12#people#4#Paris, France (General), France#FR#FR00#48.8667#2.33333#-1456928;
V1LOCATIONS: 4#Paris, France (General), France#FR#FR00#48.8667#2.33333#-1456928;1#France#FR#FR#46#2#FR
V2.1AMOUNTS: 12,people,19

These are three cells from the generated record. example.gkg.csv contains the complete 27-column GKG entry, including themes, tone, GCAM and enhanced fields. The generator resolves locations from NER and adds the nearest resolved location to each count.

The generator returns a dictionary of 27 fields. This example explicitly supplies a recognizer and empty media/extras metadata, so strict=True verifies a complete row. Missing supplied metadata or model-dependent fields without ner remain None and produce a warning. allow_incomplete=True exports those unavailable values as blank cells. Output is headerless and tab-delimited, even when the filename ends in .csv (GDELT specifics).

For non-English articles and the full GCAM profile, use the complete pipeline example in the API guide.

Field implementation map

Columns appear in output order. Model-dependent fields require an installed recognizer; missing supplied metadata remains None.

Column Standalone function Status
GKGRECORDID format_record_id Supplied metadata
V2.1DATE format_date Batch timestamp
V2SOURCECOLLECTIONIDENTIFIER format_source_collection Supplied metadata
V2SOURCECOMMONNAME source_common_name Explicit label or hostname
V2DOCUMENTIDENTIFIER document_identifier Supplied metadata
V1COUNTS extract_counts Experimental approximation
V2.1COUNTS extract_enhanced_counts Same counts with number offsets
V1THEMES extract_themes Rule-based approximation
V2ENHANCEDTHEMES extract_enhanced_themes Same theme mentions with phrase offsets
V1LOCATIONS extract_locations Offline reference gazetteer and NER approximation
V2ENHANCEDLOCATIONS extract_enhanced_locations Same resolved places with ADM2 and offsets
V1PERSONS extract_persons spaCy NER approximation
V2ENHANCEDPERSONS extract_enhanced_persons Same person mentions with offsets
V1ORGANIZATIONS extract_organizations spaCy NER approximation
V2ENHANCEDORGANIZATIONS extract_enhanced_organizations Same organization mentions with offsets
V1.5TONE extract_tone Benchmark-refined dictionary approximation
V2.1ENHANCEDDATES extract_enhanced_dates Explicit English dates with resolutions 1–4
V2GCAM extract_gcam Dictionary category counts and weighted scores; coverage depends on local dictionaries
V2.1SHARINGIMAGE format_sharing_image Supplied image URL
V2.1RELATEDIMAGES format_related_images Supplied image URLs
V2.1SOCIALIMAGEEMBEDS format_social_image_embeds Supplied social-post URLs
V2.1SOCIALVIDEOEMBEDS format_social_video_embeds Supplied video URLs
V2.1QUOTATIONS extract_quotations Quoted spans and reporting-verb approximation
V2.1ALLNAMES extract_all_names Broad named entities and proper-noun spans
V2.1AMOUNTS extract_amounts Numeric/textual quantities with bounded objects
V2.1TRANSLATIONINFO format_translation_info Supplied metadata
V2EXTRASXML extract_extras_xml Custom extension data, including supplied metadata

See the field documentation for implementation status, research, and usage for each field.

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 1.3.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 gdelt-regkg 1.3.0
File Size Uploaded Provenance Actions
gdelt_regkg-1.3.0.tar.gz 466.5 kB With provenance Details for gdelt_regkg-1.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gdelt-regkg 1.3.0
File Interpreter ABI Platform Actions
gdelt_regkg-1.3.0-py3-none-any.whl Python 3 none any Details for gdelt_regkg-1.3.0-py3-none-any.whl

Total release size: 851.8 kB

Release files / gdelt_regkg-1.3.0.tar.gz

Download URL gdelt_regkg-1.3.0.tar.gz
Size 466.5 kB
Tags Source
SHA-256 checksum
How to use checksums
81837422e7be80f21ee421bd72d964a68fee2a0b139aec79cab608416941ef34
BLAKE2b-256 checksum
How to use checksums
3d35644af62c8b1563d36351c4908e599ae731efa20af490719ad31e64c5207f
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 13, 2026.

Transparency log

Release files / gdelt_regkg-1.3.0-py3-none-any.whl

Download URL gdelt_regkg-1.3.0-py3-none-any.whl
Size 385.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6790fb5304183639ffc4e33850cfe0a9f0a0213e0d074668eac6da060eb124fc
BLAKE2b-256 checksum
How to use checksums
0c2593d502bd37ea041a6f187788b5100fc2b38dcf1ed387358a8eeae71bad85
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 13, 2026.

Transparency log

Security for gdelt-regkg 1.3.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 gdelt_regkg-1.3.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 13, 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