Skip to content

CLI Reference

gdeltforge <command> [options]

The CLI intentionally does not chain stages automatically: you run each one explicitly to maintain full control. python main.py <command> is kept as a backward-compatible alias, present only in a source checkout, not in the PyPI package; gdeltforge itself always works either way.

Command Description
scrape Download raw GDELT data (ZIP -> CSV)
convert Convert downloaded CSV files to Parquet
clean Clean converted Parquet: the data-quality stage (formerly filter)
aggregate Concatenate a period's worth of 15-minute-cadence files into one larger file per day/month/year
sample Efficient, reproducible sampling
crossref Enrich a sampled Events output with GKG (themes, tone, people, organizations)
codes Look up valid CAMEO/FIPS codes for filter values

Exit codes

scrape, convert, and clean all exit non-zero if any individual file failed, even though the ones that succeeded are kept, so a partial failure never gets missed in a &&-chained or scripted run. scrape and convert name the failed files in the error message, with each file's reason in the log output above it; clean lists each failed file with its reason in Failed: <file>: <reason> lines just above the error message, at every verbosity.

Any command that fails prints Error: <message> to stderr and exits with status 1, rather than a raw Python traceback; interrupting a command with Ctrl+C prints Interrupted. and exits with status 130. A scrape/convert/clean run backed by a worker pool cancels every not-yet-started file immediately on either signal, rather than draining the whole remaining queue first; the handful of files already in flight are still allowed to finish. A plain kill (SIGTERM, no -9) behaves the same way, printing Terminated. and exiting with status 143, since that's what most process managers (systemd, Docker, Kubernetes) send by convention before escalating.

gdeltforge makes itself its own process group leader on POSIX at startup, so kill -KILL -$(pgid) (or pkill -KILL -g $PGID) reliably stops the whole run, worker processes included, in one shot. A bare kill -9 <pid> targeting only the main process cannot be caught by anything, including this: its already-dispatched workers keep running to completion, orphaned, since SIGKILL never reaches them at all. On Windows, the equivalent whole-tree stop is taskkill /F /T /PID <pid>.

Global options

--config PATH

: Path to settings.yaml. Defaults to the GDELTFORGE_CONFIG environment variable, then ./config/settings.yaml relative to the current working directory. Use this (or the env var) to run gdeltforge from outside the repo checkout, pointing at a config file anywhere on disk.

`--config` goes **before** the subcommand, not after it, unlike every other flag documented below:

```bash
gdeltforge --config /path/to/settings.yaml scrape --dataset events
```

Placing it after the subcommand (`gdeltforge scrape --config ...`) fails with argparse's own generic `unrecognized arguments: --config ...`, since `--config` is a top-level option, not defined on any individual subcommand's own parser.

gdeltforge scrape

Download the entire archive:

gdeltforge scrape --dataset events

Download only files within a date range (any combination of bounds is valid):

gdeltforge scrape --dataset events --start-date 2020-01-01 --end-date 2023-12-31
gdeltforge scrape --dataset events --start-date 2022-01-01          # from date onward
gdeltforge scrape --dataset events --end-date   2015-12-31          # up to date
Flag Description
--dataset {events,events-15min,events-reduced,gkg-v1,gkg-v1-counts,gkg-v2,mentions} Which GDELT dataset to scrape (required; see --dataset below)
--stream {english,translated} GDELT 2.0 stream (default english). translated works on GDELT's machine-translated coverage of gkg-v2, mentions and events-15min, in its own directories; see --stream below
--start-date YYYY-MM-DD Only download files whose period starts on or after this date
--end-date YYYY-MM-DD Only download files whose period ends on or before this date
--order {asc,desc} Processing order: asc (oldest first, the default) or desc (newest first)
--verbose Show per-attempt download detail (filename, attempt N/M) instead of just the progress bar and summary. Off by default
--quiet Suppress even the default setup/summary lines, leaving only warnings and errors. Off by default
-q Shorthand for --quiet
--force Re-download files that already exist locally instead of skipping them. Off by default
--dry-run Report how many files would be downloaded and skipped, and the directory they would go to, without downloading anything. It still fetches the dataset's file listing. Off by default

--dataset gkg-v2/mentions/events-15min publish every 15 minutes rather than daily, so a wide date range can imply far more files than the equivalent daily events scrape; see --dataset below. gkg-v1/gkg-v1-counts are daily, like events, so this doesn't apply to them.

The date filter applies to all three file types the GDELT archive provides:

File type Example filename Included when
Daily 20200315.export.CSV.zip day falls within range
Monthly 202003.zip month overlaps range
Yearly 2020.zip year overlaps range

Files already present in the download directory are skipped regardless of the date filter, so re-running scrape is safe and incremental. A pre-existing file's checksum is not re-verified before it's counted as skipped: its integrity is assumed from its presence, not re-checked against GDELT's own MD5. --force re-downloads and re-verifies it if that assumption is ever in doubt (a stale or corrupted file left over from an interrupted earlier run, say). A corrupted file left in place this way is still caught reliably: convert fails clearly on a bad ZIP the moment it actually reads one.

Downloads run concurrently (scraping.max_workers, default 8) and are checksum-verified against the MD5 GDELT publishes for each file: a mismatch is treated like a network failure and retried, so a corrupted or truncated download never silently ends up in the dataset. This applies to what's downloaded during the current run; see the skip note above for what a rerun assumes about a file it finds already present. See Configuration for the requests vs selenium link-collection method and the full list of scraping settings.

--quiet raises the logger to WARNING, suppressing the setup and summary lines scrape otherwise always prints; mutually exclusive with --verbose.

--force re-downloads a file even when one with the same name is already present, overwriting it. --dry-run reports how many files would be downloaded versus skipped, honoring --force's effect on that count, without downloading any file. It still fetches the dataset's file listing from GDELT, since that is what it counts: the HTML index for events, gkg-v1 and gkg-v1-counts, and for events-15min, gkg-v2 and mentions the 15-minute master file list, whose fetch takes several seconds. Only events-reduced, a single fixed file, needs no request.

--order picks which files are submitted to the download pool first: asc (the default) matches convert/clean/sample/crossref's own existing file order, so an interrupted scrape leaves a contiguous prefix of history those stages can already process cleanly; desc prioritizes the most recent files, useful when the goal is current data rather than a full backfill. It only controls submission order, not real completion order: downloads run concurrently, so a later-submitted small file can still finish before an earlier-submitted large one.

gdeltforge convert

gdeltforge convert --dataset events

Extracts all CSV files from the downloaded ZIP archives and converts them to Parquet. Each ZIP is processed independently, so conversion runs across a pool of worker processes (converter.max_workers; null, the default, uses all available CPU cores). A bare .csv matched by converter.file_pattern (e.g. "*.csv", for a file that didn't come from a fresh scrape) is read directly instead, with no extraction step; see Configuration.

Flag Description
--dataset {events,events-15min,events-reduced,gkg-v1,gkg-v1-counts,gkg-v2,mentions} Which GDELT dataset to convert (required; see --dataset below)
--stream {english,translated} GDELT 2.0 stream (default english). translated works on GDELT's machine-translated coverage of gkg-v2, mentions and events-15min, in its own directories; see --stream below
--start-date YYYY-MM-DD Only convert files whose period starts on or after this date
--end-date YYYY-MM-DD Only convert files whose period ends on or before this date
--order {asc,desc} Processing order: asc (oldest first, the default) or desc (newest first)
--delete-source Delete each source ZIP once its parquet output is written and confirmed done. Off by default
--recover-unzipped Convert leftover CSVs sitting in unzipped_data_directory instead of the ZIPs in downloaded_data_directory. Off by default; not supported for --dataset events-reduced
--verbose Show per-file conversion detail (which ZIP is being processed, which are skipped as already done) instead of just the progress bar and summary. Off by default
--quiet Suppress even the default setup/summary lines, leaving only warnings and errors. Off by default
-q Shorthand for --quiet
--force Reprocess ZIPs already marked done instead of skipping them, overwriting their parquet output. Off by default
--dry-run Report how many ZIPs would be converted without converting anything. Off by default

--start-date/--end-date narrow which already-downloaded ZIPs get converted, the same date filter scrape applies to what gets downloaded:

gdeltforge convert --dataset events --start-date 2020-01-01 --end-date 2020-12-31

Already-converted files are skipped on a rerun, the same way scrape skips already-downloaded files; an interrupted run resumes rather than starting over. See Configuration for how that marker also tracks output_columns/compression, so a config change is reprocessed rather than skipped.

--order picks which ZIPs are submitted to the worker pool first, same meaning and same "submission order, not completion order" caveat as scrape's own --order. Unlike scrape, convert's file discovery has no inherent order of its own to preserve or override (it lists the download directory, not a remote listing), so --order is the only thing that makes this deterministic at all.

--delete-source reclaims the raw ZIP's disk space once its parquet output is confirmed written, so a full historical pull doesn't need to hold the raw archive and the converted output at once. Only the ZIP; the intermediate extracted CSV is already removed unless converter.keep_unzipped is set. Never deletes on a failed conversion, and never runs ahead of the .done marker. Combined with output_columns, the columns it dropped can't be recovered later without re-scraping the original file, so a warning fires once at the start of a run configured that way.

--recover-unzipped is for the CSV a normal run leaves behind: the extraction step succeeded but the parquet write itself failed, or converter.keep_unzipped kept the CSV around after a config change invalidated its .done marker, and by the time someone wants to retry, the source ZIP is gone (--delete-source already removed it, or it was cleaned up by hand). A plain rerun of convert only looks at downloaded_data_directory, so it can't see that CSV at all; this flag points the same conversion logic at unzipped_data_directory instead, with its own .done tracking keyed on the CSV rather than the ZIP. It never runs as part of a normal convert; call it deliberately once you know a ZIP is missing. Not supported for --dataset events-reduced, which streams and partitions its single source file directly rather than leaving a per-file CSV behind.

By default convert shows a setup line, a progress bar, and an end-of-run summary, the same shape scrape always has. At gkg-v2/mentions scale (hundreds of thousands of 15-minute files) the per-file detail this used to always print became hundreds of thousands of terminal lines fighting the progress bar for the screen; --verbose restores it for whoever actually wants to watch file-by-file. --quiet goes the other way, raising the logger to WARNING and suppressing even the setup/summary lines; mutually exclusive with --verbose.

--force bypasses the .done marker check, reprocessing and overwriting output for ZIPs already converted under the current configuration. --dry-run reports how many ZIPs would be converted, honoring --force's effect on that count, without processing anything.

See Configuration for the optional Hive-partitioning feature for pre-2013 yearly/monthly source files.

gdeltforge clean

gdeltforge clean --dataset events

The data-quality stage: drops rows with missing values in the columns defined under clean.columns_to_check.<dataset> in settings.yaml, then shapes each file's output (output_columns, float32_columns, compression) and writes it to cleaned_data_directory. Each file is cleaned independently, so cleaning runs across a pool of worker processes too (clean.max_workers; null, the default, uses all available CPU cores). On network storage, io.max_concurrent_reads caps that pool further; see Configuration. It decides whether a row is usable at all; which rows are relevant to a research question is decided at sampling time, with sample --mode filtered --filter. Data Cleaning explains that split, the order of the stage's steps, and the decision behind each behavior.

Renamed from filter in 0.12.0

Before 0.12.0 this stage was gdeltforge filter, and its name collided with sample's unrelated --filter option. The old names keep working through the 0.12.x series, each with a deprecation warning: the gdeltforge filter command, the filter: config section, the *filtered_data_directory/*filtered_historical_directory path keys, and --source filtered in sample/aggregate/crossref. Output files are now named <stem>_cleaned.parquet; cleaning a file removes the same source's pre-0.12 <stem>_filtered.parquet from the output directory, so a directory never holds both copies of the same day.

Flag Description
--dataset {events,events-15min,events-reduced,gkg-v1,gkg-v1-counts,gkg-v2,mentions} Which GDELT dataset to clean (required; see --dataset below)
--stream {english,translated} GDELT 2.0 stream (default english). translated works on GDELT's machine-translated coverage of gkg-v2, mentions and events-15min, in its own directories; see --stream below
--start-date YYYY-MM-DD Only clean files whose period starts on or after this date
--end-date YYYY-MM-DD Only clean files whose period ends on or before this date
--order {asc,desc} Processing order: asc (oldest first, the default) or desc (newest first)
--delete-source Delete each source (converted) parquet once its cleaned output is written and confirmed done. Off by default
--verbose Show per-file clean detail (rows kept per file, which are skipped as already done) instead of just the progress bar and summary. Off by default
--quiet Suppress even the default setup/summary lines, leaving only warnings and errors. Off by default
-q Shorthand for --quiet
--force Reprocess files already marked done instead of skipping them, overwriting their cleaned output. Off by default
--dry-run Report how many files would be cleaned without cleaning anything. Off by default
--report With --dry-run: read every file in scope and report what each step would change (rows removed, values repaired, columns kept, unrecognized codes). Slower than a plain --dry-run, since it reads the data. Off by default

The stage refuses to start if cleaned_data_directory (or cleaned_historical_directory) is a converted-data directory or sits inside one. Cleaned files there would sit beside the converted files they came from: the next run would clean its own output again, and every reader of the converted directory would count those rows twice. The converted directory stays the copy to return to.

Each run writes an audit next to the cleaned directory (<cleaned_data_directory>_runs/ unless paths.clean_runs_directory says otherwise), one row per cleaned file (rows in and out, unrecognized codes per coded column), and every cleaned file carries a gdeltforge:clean metadata entry naming its steps and source; see Data Cleaning.

--start-date/--end-date narrow which already-converted Parquet files get read. This restricts which files get cleaned, not the rows within them: the null check itself is a concern unrelated to date.

Already-cleaned files are skipped on a rerun too, tracked the same way as convert's marker; see Configuration for which settings (columns_to_check, output_columns, float32_columns, compression) invalidate it.

--order picks which files are submitted to the worker pool first, same meaning as convert's own --order. When Hive-partitioned historical data is configured, flat and historical files are ordered together as one sequence, not each sorted independently and concatenated, so desc genuinely surfaces the single newest file across both first rather than just the newest of whichever group happens to be listed first.

--delete-source reclaims the converted parquet's disk space once its cleaned output is confirmed written, so a full historical pull doesn't need to hold both copies at once. Never deletes on a failed file, and never runs ahead of the .done marker. Two real costs worth knowing before turning it on: combined with columns_to_check/output_columns/float32_columns, whatever those narrowed away can't be recovered later without re-converting from the raw ZIP (a warning fires once at the start of a run configured that way), and it also removes the option to later sample --source converted against the uncleaned data.

By default clean shows the same setup line, progress bar, and end-of-run summary shape as convert/scrape. Its per-file line is quieter than convert's (one line per file instead of two), but at gkg-v2/mentions scale it's still hundreds of thousands of lines; --verbose restores it, same reasoning as convert's own flag. --quiet goes the other way, raising the logger to WARNING and suppressing even the setup/summary lines; mutually exclusive with --verbose.

--force bypasses the .done marker check, reprocessing and overwriting output for files already cleaned under the current configuration. --dry-run reports how many files would be cleaned, honoring --force's effect on that count, without processing anything; add --report to also measure what each step would change, which reads every file in scope. --report without --dry-run is an error.

With the default settings, clean also repairs known GDELT errors (the events dated 1920 instead of 2020, and the blank DATEADDED of the 2013-09-01 and 2013-09-02 daily files) while keeping GDELT's own values, and counts the rows that aren't CAMEO events; see Data Cleaning. --delete-source refuses to run while a lossy step added in 0.12.0 is configured (event_markers: drop, date_1920 without keep_original, either normalize switch, or places.resolve) unless clean.allow_lossy_delete_source is true.

gdeltforge aggregate

gdeltforge aggregate --dataset gkg-v2 --period day

GKG 2.1, Mentions, and events-15min are the only datasets discovered from GDELT's 15-minute gdeltv2 master file list, so a single calendar day is routinely split across ~96 separate files. aggregate concatenates a period's worth of them (day, month, or year) into one larger file, so sample (and IndexedSampler's FileIndex in particular, which opens every file's footer to build its global row index) reads far fewer, larger files instead. Pure concatenation, not a statistical rollup: every row from every contributing file lands in the aggregated output unchanged, no deduplication or summing. It removes per-file overhead (a full-archive FileIndex build went from 2.5 hours to 50 s on a network share) and the larger row groups compress better, but a full scan still reads every row. See Configuration for the measured numbers, memory included. Periods run across a pool of worker processes (aggregation.max_workers, capped by io.max_concurrent_reads when set), each reading one source file at a time.

Flag Description
--dataset {gkg-v2,mentions,events-15min} Which 15-minute-cadence GDELT dataset to aggregate (required). Every other dataset already publishes at day-or-coarser granularity, so there's nothing for this to solve there
--stream {english,translated} GDELT 2.0 stream (default english). translated works on GDELT's machine-translated coverage of gkg-v2, mentions and events-15min, in its own directories; see --stream below
--period {day,month,year} Granularity to concatenate into (default day, matching sample --mode calendar's own default)
--source {cleaned,converted,filtered} Which stage's output to aggregate from (default cleaned; filtered is its deprecated pre-0.12 name). Recorded as part of this run's resumability fingerprint, so switching source for an already-aggregated period reprocesses and overwrites it rather than mixing the two
--start-date YYYY-MM-DD Only aggregate periods whose source files' period starts on or after this date
--end-date YYYY-MM-DD Only aggregate periods whose source files' period ends on or before this date
--order {asc,desc} Processing order: asc (oldest period first, the default) or desc (newest first)
--delete-source Delete each contributing source file once its period's aggregated output is written and confirmed done. Off by default: the safe default keeps the aggregated output in its own separate directory alongside the untouched source files
--verbose Show per-period aggregation detail instead of just the progress bar and summary. Off by default
--quiet Suppress even the default setup/summary lines, leaving only warnings and errors. Off by default
-q Shorthand for --quiet
--force Reprocess periods already marked done instead of skipping them, overwriting their aggregated output. Off by default
--dry-run Report how many periods would be aggregated without aggregating anything. Off by default

Unlike convert/clean, whose .done marker is keyed one-per-source-file, aggregation is many-sources-in-one-output: the marker sits next to each aggregated output file, fingerprinted on this run's own settings (--source, compression, --delete-source) plus the sorted set of contributing source filenames. The output file itself records its sources, in the order their rows were written, with the converted 15-minute file each holds and its row count (Parquet metadata, key gdeltforge:aggregate), so a sample's --provenance can name a row's 15-minute file (see Row provenance). A period whose source-file-set later changes (a backfilled/delayed 15-minute file, or a still-in-progress day that later gets a file added) is reprocessed rather than treated as permanently done just because a marker with a matching config exists.

--order, --verbose/--quiet, --force, and --dry-run all match convert's/clean's own identically-named flags exactly, including the worker-pool interrupt handling (Ctrl+C/SIGTERM cancel not-yet-started periods immediately rather than draining the whole batch).

Read the aggregated output back with sample --source aggregated --period day (see gdeltforge sample below); --dataset there must be one of the same three eligible datasets.

--dataset

scrape, convert, clean, and sample all accept --dataset {events,events-15min,events-reduced,gkg-v1,gkg-v1-counts,gkg-v2,mentions}, and require it: there's no default, so every invocation of these four commands names its dataset explicitly. This was a deliberate breaking change (see the changelog): with two Events-flavored choices now available, a silent default risked someone meaning to opt into the finer, slower one falling back to the daily archive instead with no error.

  • events: the daily/monthly/yearly Events archive. Not real-time (updates once a day), but far smaller and faster than events-15min for the same date range.
  • events-15min: Events at native GDELT 2.0 granularity, discovered from the same 15-minute master file list as gkg-v2/mentions, not the daily archive's directory listing. Genuinely a different, richer schema, not just finer granularity: 61 columns against the daily archive's 58, with an ADM2Code field added to each of the three geo blocks (Actor1Geo/Actor2Geo/ActionGeo) that the older, GDELT-1.0-compatible daily format doesn't carry. Opt-in and much slower in practice: real measurement puts the full 2015-present archive at 396,086 files (~81x the daily archive's file count for the same span) and ~40 GB total. File count, not raw size, is what dominates the cost here, since Events rows are compact structured data rather than GKG's free text. Reach for this only when you need intraday freshness or the extra geo precision; events is the right default-shaped choice otherwise.
  • events-reduced: GDELT.MASTERREDUCEDV2.1979-2013.zip, a single static historical dump (~1.08 GB zipped, ~87.3M rows uncompressed), pre-aggregated on DATE+ACTOR1+ACTOR2+EVENTCODE rather than one row per event. Carries no GlobalEventID, SOURCEURL, or DATEADDED, so crossref can't run against it, and --start-date/--end-date are rejected on scrape for it (the file has no per-day/month/year filename to narrow by). convert always writes it Hive-partitioned by Year, computed from its own Date column; see Configuration for the full description.
  • gkg-v2: GKG 2.1, the current, actively-produced Global Knowledge Graph (themes, tone, GCAM, people, organizations; see Configuration). Discovered and downloaded differently from Events under the hood (a 15-minute-interval master file list, not a directory listing); see Configuration.
  • mentions: every re-report of an Event by a different article over time, the bridge table a real Events<->GKG join goes through, since GKG 2.1 itself carries no event ID (see Related Work).
  • gkg-v1: the legacy GKG format (April 2013 through February 2015 as the primary feed, still published daily since). Unlike GKG 2.1, each row carries EventIds directly, so it joins to Events without the two-hop trip through Mentions. Daily files, discovered the same way as Events but from a different URL (see Configuration).
  • gkg-v1-counts: GKG 1.0's separate "Counts" file, one row per individual count mention (e.g. one row per "12 killed" statement) rather than one row per document.

--stream

GDELT 2.0 publishes two streams of events-15min, mentions and gkg-v2: the English one, and a machine-translated one covering news in 65 other languages, with the same columns in separate files (20230601080000.translation.export.CSV.zip, ...translation.mentions.CSV.zip, ...translation.gkg.csv.zip) listed in masterfilelist-translation.txt. The translated stream holds about a third of GDELT 2.0's events; the daily events archive holds none of them.

scrape, convert, clean, aggregate and sample accept --stream {english,translated} (default english). With translated, scrape reads the translated list, and every command reads and writes the dataset's paths.translated_* directories in place of its English ones, so one config holds both streams side by side:

gdeltforge scrape    --dataset events-15min --stream translated --start-date 2023-06-01 --end-date 2023-06-30
gdeltforge convert   --dataset events-15min --stream translated
gdeltforge clean     --dataset events-15min --stream translated
gdeltforge aggregate --dataset events-15min --stream translated --period day
gdeltforge sample    --dataset events-15min --stream translated --mode indexed -n 1000 --source aggregated --out translated.parquet

Each step works on one stream; a sample of both is two samples. crossref also takes --stream both, joining an event's mentions from both streams at once (Both streams). Every other dataset has no translated stream, and --stream translated with it stops with an error. The directories are in Configuration.

gdeltforge sample

The three sampling modes, indexed, calendar and filtered, plus stratified as filtered's own optional sub-mode

All sampling modes read from the cleaned directory by default; pass --source converted to sample from raw converted Parquet instead, before the clean stage's NaN-dropping, or --source aggregated to read gdeltforge aggregate's output instead (--dataset must be one of the three 15-minute-cadence datasets aggregate supports: gkg-v2/mentions/events-15min).

Flag Applies to Description
--dataset {events,events-15min,events-reduced,gkg-v1,gkg-v1-counts,gkg-v2,mentions} all Which GDELT dataset to sample from (required; see --dataset above)
--stream {english,translated} all GDELT 2.0 stream to sample (default english); see --stream
--mode {indexed,filtered,calendar,daily} all Sampling strategy (required). daily is a deprecated alias for calendar (period=day)
--source {cleaned,converted,aggregated,filtered} all Which stage's output to read from (default cleaned; filtered is its deprecated pre-0.12 name). aggregated reads gdeltforge aggregate's output; combine with --period to pick which granularity
-n N indexed, filtered Number of rows to sample (default 1000). Not with --stratify, where --n-per-group sizes the sample: given there, or in calendar mode, it's ignored with a warning
--replace indexed, filtered (without --stratify) Sample with replacement: duplicate rows are possible, and n may exceed the total row count. Off by default; rejected for --mode calendar/daily and for --stratify
--seed N all RNG seed (default 42)
--provenance all Add SourceFile and SourceRow to every sampled row: the converted file it comes from and its 0-based position there, the 15-minute file for --source aggregated (see Row provenance). Off by default
--file-index PATH all The saved file index to read and update, in place of the one under paths.index_directory (see Saved file index)
--per-period N calendar Rows per calendar period (default 10); with --quota-file, the rows of each period the file doesn't list (default 0)
--per-day N calendar Deprecated alias for --per-period
--period {day,month,year} calendar, --source aggregated Two independent uses, default day for both: in calendar mode, the period to group by (rejected alongside the deprecated --mode daily); with --source aggregated, which of the day/month/year aggregated directories to read, for any --mode. They combine naturally when both apply
--date-column COLUMN calendar Date column to group by (default depends on --dataset: Day for events/events-15min, Date for events-reduced/gkg-v1/gkg-v1-counts, V2.1DATE for gkg-v2, MentionTimeDate for mentions)
--filter JSON filtered JSON filter dict, e.g. '{"QuadClass": [1,2]}': column conditions, the operators equals, in_list, gt, lt, between, is_null, is_blank, and the blocks AND, OR, NOT, ANY, ALL (syntax)
--columns COL [COL ...] all Restrict output to these columns; cuts I/O and memory on the full archive
--stratify COLUMN filtered Stratify by this column; requires --n-per-group or --quota-file
--n-per-group N filtered Rows per stratum when --stratify is set; with --quota-file, the rows of each stratum the file doesn't list (default 0)
--quota-file PATH calendar, --stratify CSV with the header group,count: the rows to draw from each period or stratum (see Quotas per group)
--start-date YYYY-MM-DD all Only sample from files whose period starts on or after this date
--end-date YYYY-MM-DD all Only sample from files whose period ends on or before this date
--out PATH all Output parquet file (default sample.parquet)
--export-format {parquet,csv} all Output file format. csv rewrites --out's extension to .csv. Off (parquet) by default

--start-date/--end-date narrow which files each mode reads before it does anything else, the same file-level date filter scrape/convert/clean/crossref already apply (reusing filter_paths_by_date). In filtered mode this stacks with --filter's own row-level predicate pushdown rather than replacing it: the date range prunes which files even get opened, --filter then narrows rows within whatever remains. Setting both together logs a warning, since a result narrower than either constraint alone implied is otherwise easy to misread as a bug.

--export-format csv is meant for handing a finished sample to a tool that doesn't read Parquet (Excel, a quick spreadsheet look), not as a second internal storage format: CSV itself has no typed schema, so a numeric-looking string column (EventCode, EventBaseCode, EventRootCode; their zero-padded values, "020", are meaningful) reads back as a plain integer, leading zero dropped, under a standard CSV reader's own default type inference, including a bare pl.read_csv/pd.read_csv call. A <name>.csv.schema.json sidecar is written alongside the CSV recording every column's real dtype; gdeltforge.utils.io.read_csv_export(path) reads it back through that sidecar for a fully lossless round trip (confirmed against real content, including null vs. genuine-empty-string values), and is the right way to read a gdeltforge CSV export back in Python. A plain CSV reader with no sidecar to consult, or a --out file moved away from its sidecar, still hits the original limitation; a warning naming the affected columns and a manual schema_overrides fix fires at export time either way.

--columns isn't always a strict projection

Each sampling mode has its own idea of which columns it can't function without, and always keeps them in the output regardless of what --columns requests:

  • indexed: a true strict projection. Output is exactly the columns named in --columns, or the dataset's full declared schema if --columns is omitted.
  • calendar: the grouping column (--date-column, or the per-dataset default) is always kept, even if --columns doesn't name it.
  • filtered/stratified: every column your --filter condition or --stratify reads is always kept, even if --columns doesn't name it. crossref's own --columns behaves the same way for its join key.

This is deliberate, not a bug: a mode can't group or filter by a column it silently dropped from the scan. A column --columns drops for real is anything not covered by one of those cases above.

--seed across a re-chunked archive

A rerun against the exact same files always reproduces the same sample, for every mode. Only --mode indexed also reproduces the same sample after the same logical rows get re-chunked into a different number of files; calendar and stratified sampling aren't guaranteed to at real archive scale. See Limitations for the full explanation, including a note on calendar/stratified reproducibility across the 0.10.0 upgrade specifically.

Row provenance

--provenance adds two columns, last, to every sampled row, in every mode: SourceFile, the converted file the row comes from, relative to its directory (20150301.export.parquet, or Year=2003/... for a historical partition), and SourceRow, the row's 0-based position in that file. A row identified this way can be found again in any version of the same data, which GlobalEventID can't do: GDELT reuses some IDs across files.

Sampling cleaned data, a row names the converted file its cleaned file was made from (the clean marker records it), at the same position: clean keeps every row, in order, unless a step drops rows. Each cleaned file's marker records its rows in and out; a file that lost rows (a columns_to_check null check, or errata.event_markers: drop) stops the sample with an error, since its positions no longer match the converted file's. The default clean settings drop no row.

A draw's rows can then be read again from any other version of the same files, cleaned with other settings, at the same (SourceFile, SourceRow), and paired row for row with the draw.

With --source aggregated, a row names the converted 15-minute file it came from and its position there, the same as a draw from the 15-minute files would. aggregate records in each file it writes the files it concatenated, in order, with the converted file each holds and its rows. A file aggregated before 0.16.0 has no such record: its .done marker lists its sources and whether they were the cleaned or the converted files, and they are read from that directory: about 96 footers per day file, a few at a time under io.max_concurrent_reads: about 340,000 footers for a draw over the whole translated Events archive. Read cold from a network share, that first draw ran for about 25 minutes. The record derived is kept in the saved file index, so a later sample over the same unchanged files reads none of those footers again and runs about as fast as one without --provenance; aggregate --force for a period writes the record into its file.

The sources are checked when the record is derived. A source that is gone stops the sample with an error naming the aggregated file; re-run gdeltforge aggregate --force for its period while its sources are on disk, or sample it without --provenance. An aggregated file whose rows no longer add up to its sources' (a source rewritten since) stops the sample the same way. A record kept in the saved file index is reused while the aggregated file keeps its size and modification time, whatever happens to its sources afterwards: a draw still labels its rows once the sources are moved away or deleted.

gdeltforge sample --dataset events --mode calendar --per-period 20 --provenance --out draw.parquet

Saved file index

Every sample first reads each file's footer: its rows, row groups and columns. Over the 368,388 files of the translated Events 15-minute stream on a network share, that alone ran for hours and passed 60 GB before it was stopped. sample keeps those facts in a saved file index, one per source directory under paths.index_directory (default ./data/index), and on a later run reads only the footers of files that are new or whose size or modification time changed; the others cost one stat each. The rows drawn are the same with or without it.

--file-index PATH reads and updates the index at PATH instead. paths.index_directory: null keeps no index, reading every footer on every run. The index is a cache: deleting it only costs the next run its footer reads, and one that can't be read or written is rebuilt or skipped with a warning. Like the clean run audit, it must sit outside every data directory. A file removed from the directory leaves the index at its next save. Footers are read a few at a time, under the limit io.max_concurrent_reads sets. For an aggregated file written before 0.16.0, the index also keeps the record of its sources a --provenance sample derived (see Row provenance); an index saved by 0.15.0 is read and extended, not rebuilt.

Sample manifest

Every sample is written with <out>.manifest.json beside it, a record of how it was drawn:

  • gdeltforge: the version that drew it, and command, the command line.
  • draw: the settings: dataset, stream (english or translated; a manifest from before 0.16.0 has none, and its sample is English), source, mode, seed, date range, columns, provenance, and the mode's own: -n and --replace, --filter, --stratify and --n-per-group, --period and --per-period, and the quotas of a --quota-file, written out in full. With a quota file and no --n-per-group or --per-period, that count is null: a group the file doesn't list draws no rows.
  • input: the source directories, how many files were read and their rows, and sha256, a hash over each file's path within its directory, its size in bytes and its row count. A file added, removed, renamed, or rewritten to another size or row count changes it. A file rewritten to the same size and row count leaves it unchanged: it names the files read, it does not hash their content. For that, keep the files' own checksums.
  • output: the file's name, format, rows, columns and sha256.
  • strata: the name of the .strata.json sidecar, for a calendar or stratified sample.

The command and the directories are local paths, so read the manifest before sharing it. Writing it is best-effort, as the strata sidecar's is: a failure logs a warning and leaves the sample in place.

Indexed sampling (uniform random)

gdeltforge sample --dataset events --mode indexed -n 10000 --seed 123 --out sample.parquet

Samples 10,000 rows uniformly across the entire dataset.

gdeltforge sample --dataset events --mode indexed -n 10000 --replace --out bootstrap.parquet

Samples 10,000 rows with replacement: duplicates are possible, and n can exceed the dataset's total row count. This is a true simple random sample with replacement, since --mode indexed already knows the exact population size upfront; useful for a bootstrap-style draw, not just a plain SRS.

Calendar sampling (N rows per period)

gdeltforge sample --dataset events --mode calendar --per-period 20 --out daily.parquet

Samples 20 rows per day across the entire period covered by your downloaded data. The cap holds per calendar period regardless of how many files that period's rows are spread across (a historical yearly file, or GKG 2.1/Mentions' many-files-per-day cadence), unlike the deprecated daily mode's own per-file cap.

Group by month or year instead of day, and by a different dataset's own date column:

gdeltforge sample --dataset gkg-v2 --mode calendar --period month --per-period 50 --out monthly.parquet

The period count can badly exceed intuition

--period day groups strictly by the grouping column's own YYYYMMDD value, not by which file a row came from. GDELT's own event-date misdating means a single day's file can legitimately carry Day values spanning a decade (a wire report referencing a much older date, a source article with a malformed or placeholder date), so the number of distinct periods a run actually produces can be far larger than "one per file downloaded" suggests. This is a real property of the underlying data, not a bug in the grouping itself.

Dates before 1979 are GDELT's 1920-for-2020 error

GDELT wrote the year 1920 for 2020 in events it added from 2019-12-31 to 2020-01-05. In uncleaned data those rows form false periods (1920-01-01 to 01-06, each drawing a full --per-period) while the real first days of 2020 come out nearly empty. Calendar sampling warns with the row count whenever it meets a date before 1979, GDELT's first year. clean repairs these dates by default (Data Cleaning), so sampling --source cleaned avoids it.

Equal allocation, not proportional

--per-period draws the same count from every period regardless of how many rows that period actually has. A quiet day and a busy day both contribute --per-period rows, so the pooled sample deliberately does not reproduce the archive's real day-to-day volume: an unweighted statistic computed on the output (an overall rate, a class share) is biased toward low-volume periods relative to the true archive. This is what makes calendar sampling useful for even temporal coverage; it's also why it isn't a drop-in for --mode indexed when the goal is a population-representative estimate rather than coverage. See Limitations.

Filtered sampling (JSON filters)

5,000 events whose QuadClass is in {1, 2}:

gdeltforge sample \
    --dataset events \
    --mode filtered \
    --filter '{"QuadClass": [1, 2]}' \
    -n 5000 \
    --out qc12.parquet

2,000 "Verbal Cooperation" events that happened in the USA:

gdeltforge sample \
    --dataset events \
    --mode filtered \
    --filter '{"ActionGeo_CountryCode": ["US"], "QuadClass": [1]}' \
    -n 2000

Selecting specific columns keeps memory use down:

gdeltforge sample \
    --dataset events \
    --mode filtered \
    --filter '{"ActionGeo_CountryCode": ["US"], "QuadClass": [1]}' \
    --columns GlobalEventID Year Actor1Code \
    -n 1000

Filters support nested AND/OR blocks; see the example pipelines below for an OR example across multiple columns.

--replace also works here (without --stratify): gdeltforge sample --dataset events --mode filtered --filter '{"QuadClass": [1, 2]}' -n 5000 --replace samples the filtered rows with replacement. Unlike indexed, the filtered row count isn't known upfront, so this first counts the filtered rows (a scan of the filter's columns only) before drawing n positions with replacement. The chosen rows are then read as for any filtered draw: the only extra cost is that one scan of the filter's columns.

Two country-code schemes, easy to mix up

GDELT has two distinct country-code schemes: Actor1CountryCode/Actor2CountryCode use 3-letter CAMEO codes (USA), while ActionGeo_CountryCode, Actor1Geo_CountryCode, and Actor2Geo_CountryCode use 2-letter FIPS 10-4 codes (US). A value that doesn't match the right scheme for its column logs a warning rather than failing outright (FIPS 10-4 was retired in 2008 and can lag newer countries), but it also means the filter silently matches nothing. Run gdeltforge codes to check.

Stratified sampling (fixed N per group)

Combines a filter with stratified reservoir sampling: draws exactly --n-per-group rows for each distinct value of a chosen column, producing a class-balanced dataset regardless of the natural distribution.

gdeltforge sample \
    --dataset events \
    --mode filtered \
    --filter '{"ActionGeo_CountryCode": ["US"]}' \
    --stratify QuadClass \
    --n-per-group 500 \
    --out stratified.parquet

This produces 500 USA events per QuadClass value. --stratify requires --n-per-group or --quota-file; -n is ignored when --stratify is set.

Alongside stratified.parquet, this also writes stratified.parquet.strata.json, recording each QuadClass value's true row count in the (USA-filtered) archive, independent of --n-per-group. Calendar sampling writes the equivalent <out>.strata.json keyed by period instead. Either sidecar is the N_h a caller needs to post-stratification-reweight the equal-allocation sample back toward the population; see Filtered Sampling and Limitations. Writing it is best-effort: a failure (a read-only output directory) logs a warning rather than failing the sample.

Quotas per group

--quota-file PATH gives each calendar period or stratum a count of its own, for a design that isn't the same count everywhere (proportional or Neyman allocation, a pilot's sizes, a top-up of chosen groups). The file is a CSV with the header group,count and one row per group:

group,count
1,4000
2,1500
4,800
gdeltforge sample --dataset events --mode filtered --stratify QuadClass     --quota-file quadclass_quotas.csv --out stratified.parquet

A group is named as the .strata.json sidecar names it: a stratum by its value as text (1, USA), with __NA__ for a null value; a period by the date column's first digits (20200101 for a day, 202001 for a month, 2020 for a year). The sidecar of an earlier run lists every group with its true row count, ready to turn into quotas. A group the file doesn't list draws --n-per-group (or --per-period) rows when that flag is given, and none otherwise; a group listed with a count of 0 draws none. A listed group no row falls in, most likely a mistyped name, is warned about. Each group draws from its own random stream, so a group's rows are the ones it draws with that count as --n-per-group, whatever the other groups' counts. --quota-file applies to --mode calendar and to --stratify; other draws refuse it.

Sampling from aggregated files

gdeltforge aggregate --dataset gkg-v2 --period day
gdeltforge sample --dataset gkg-v2 --mode indexed --source aggregated --period day -n 10000

Reads from gdeltforge aggregate's output directory instead of cleaned_data_directory/parquet_data_directory; every mode works the same way against it. --period picks which of the day/month/year aggregated directories to read, independent of --source cleaned/converted's own choice of which directory aggregate itself read from when building the aggregated files.

gdeltforge crossref

GKG 2.1 joins to Events in two hops through Mentions on the article URL; GKG 1.0 joins directly on EventIds

Enriches a sampled Events output with GKG: themes, tone, people, organizations extracted from the news coverage of each event. Takes a Parquet file (the output of gdeltforge sample) rather than the full archive, since joining against the entire Events dataset by default would be a much heavier operation than enriching a bounded sample.

Nothing stops --events from actually pointing at the full archive (or a directory of files) instead, since a genuinely archive-scale join is sometimes exactly what's wanted, so this isn't blocked, but it logs a warning (not a hard stop, matching how a large scrape already warns) once --events crosses 1,000,000 rows: every file in the configured Mentions/GKG directory gets scanned regardless of --events size, and just building the join key set was measured at roughly 100 MB and a second per million events (10M: ~800 MB; 50M: ~5.2 GB), before that scan even starts. If that wasn't intentional, run gdeltforge sample first.

The configured Mentions/GKG directory itself gets the same treatment, independent of --events size: past 50,000 files, a warning fires for that directory specifically (Mentions/GKG 2.1/GKG 1.0 checked separately, so either one being the large one is called out by name), since crossref lists and opens every file in it on every run, regardless of how selective the join ends up being (real measurement: ~75 microseconds/file, so ~29s for the full historical GKG 2.1/Mentions archive just to list and open, before a single row is read). --start-date/--end-date, same as scrape/convert/clean, narrow which files in that directory get listed and opened at all; pointing paths.* at a smaller, already-narrowed directory reduces it further. Both flags only narrow the Mentions/GKG side, not --events: a Mentions row is timestamped by when it was recorded, not by its event's DATEADDED (see auto's description below), so narrowing by date can exclude a legitimate late mention of an in-range event, a real scope decision rather than a risk-free filter.

gdeltforge crossref --events sample.parquet --gkg-version v2 --out enriched.parquet
Flag Description
--events PATH Parquet file of Events rows to enrich (required). A directory of parquet files also works (e.g. convert/clean output directly); .done resumability markers in it are ignored
--gkg-version {v1,v1-counts,v2,auto} Which GKG generation to join against (required, see below)
--stream {english,translated,both} Which GDELT 2.0 stream's Mentions and GKG 2.1 to join against (default english). both reads the two streams at once and adds a Mention_Stream column; see Both streams below. v2/auto only: v1/v1-counts reject any stream but english, and auto's GKG 1.0 path stays English
--source {cleaned,converted,aggregated,filtered} Which stage's GKG/Mentions output to read from (default: cleaned; filtered is its deprecated pre-0.12 name). aggregated reads gdeltforge aggregate's Mentions and GKG 2.1 output, --gkg-version v2 only (GKG 1.0 has no 15-minute files to aggregate)
--period {day,month,year} With --source aggregated: which of the day/month/year aggregated directories to read (default day); rejected with any other --source
--columns COL [COL ...] Restrict GKG-side output to these columns, named either the raw GKG dataset's own way (Date, Tone) or the way they actually appear in this command's output (GKG_Date, GKG_Tone); the join key column is always included regardless and is never a valid name here. Not supported with --gkg-version auto
--on-duplicate-document {latest,earliest,all} When GKG 2.1 carries more than one record for the same article URL: keep all of them, one row per record (default), or narrow to just the most recent or the earliest record. Only affects v2/auto; setting it alongside v1/v1-counts logs a warning and has no effect
--collapse-duplicate-mentions Collapse per-sentence duplicate mentions of the same event in the same article into one row with an explicit Mention_Count column, instead of keeping every raw Mentions row (the default). Only affects v2/auto; setting it alongside v1/v1-counts logs a warning and has no effect
--start-date YYYY-MM-DD Only join against GKG/Mentions files whose period starts on or after this date. Narrows the configured directories being read, not --events
--end-date YYYY-MM-DD Only join against GKG/Mentions files whose period ends on or before this date. Narrows the configured directories being read, not --events
--out PATH Output parquet file (default crossref.parquet)
--export-format {parquet,csv} Output file format. csv rewrites --out's extension to .csv. Off (parquet) by default; see sample's own --export-format above for the CSV round-trip caveat

GKG's two format generations relate to Events differently, so --gkg-version picks a genuinely different join strategy, not just a different data source (see Related Work for why a direct Events<->GKG 2.1 join isn't possible):

  • v1 and v1-counts: GKG 1.0 (and its separate Counts file) carry EventIds directly on each row, a comma-delimited list, so this is a direct join. GKG 1.0 has been live and daily since 2013-04-01.
  • v2: GKG 2.1 carries no event id at all, only the source article's URL, so this is a two-hop join through Mentions: Events -> Mentions (on GlobalEventID) -> GKG 2.1 (on that URL). GKG 2.1 and Mentions didn't exist before GDELT 2.0 launched, 2015-02-18. GKG 2.1 is read in two passes: first only the URL column of every file in range, then the requested columns of only the files holding a match, a few files at a time (io.max_concurrent_reads, else 4; an exported POLARS_MAX_CONCURRENT_SCANS takes precedence), so memory follows the matched articles and one batch of files, not the size of the archive.
  • auto: attempts every eligible event against both v1 and v2 instead of requiring one version for the whole sample, or picking exactly one per event. DATEADDED only decides eligibility (events before 2013-04-01 have no data in either generation and are skipped with a warning), not which single path is allowed to match: a Mentions row is timestamped by when it was created, not by its event's DATEADDED, so an event from the GKG 1.0 era can still have a real GKG 2.1 match created much later, and GKG 1.0 remains live today, so a recent event isn't guaranteed to be GKG-2.1-only either. This is the one to reach for when a sample spans both eras, e.g. a broad historical sample that includes the 2013-2015 window where only GKG 1.0 exists. Output carries a CrossrefSource column (v1 or v2) marking which path produced each row; an event that genuinely matches both contributes one row per path, not a merged or arbitrarily-chosen row. The two schemas' GKG-side columns don't overlap at all (11 GKG 1.0 fields vs 27 GKG 2.1 fields, different names throughout) and aren't unified: a row carries NaN for whichever set its source path didn't produce.

Both v1/v1-counts and v2 preserve the underlying many-to-many structure rather than collapsing it: one event can produce several output rows (several articles covered it, each contributing its own GKG data), and one article covering several events contributes one row per event, not one merged row. An event with no GKG match contributes no rows at all, rather than a row full of nulls. GKG-side output columns are prefixed GKG_ (and, for v2, Mentions bridge fields Mention_) to avoid colliding with an identically-named Events column, e.g. NumArticles exists on both Events and GKG 1.0.

v2's two-hop join has two further, independent sources of repeated rows for what's really the same (event, article) pair, each controlled by its own flag above, both defaulting to keeping everything rather than silently discarding anything: GKG 2.1 occasionally carries more than one record for the same document URL, all of them kept by default (--on-duplicate-document), and Mentions records one row per sentence that references an event, so an event quoted several times in one article produces several near-identical raw rows, also kept uncollapsed by default (--collapse-duplicate-mentions to fold them into one row with a Mention_Count column instead). See Crossref Join Semantics for the real-data numbers behind both.

Both streams

An event's coverage is split across GDELT's two streams: translated mentions refer to English events, and English mentions to translated ones. --stream both reads Mentions and GKG 2.1 from both streams' directories, for v2 and for auto's GKG 2.1 path. Each mention's document is looked up in its own stream's GKG 2.1 files, since no GKG document of either stream has a mention in the other. The output gains a last column, Mention_Stream (english or translated), naming the stream of each row's mention. Each stream is joined on its own and the results follow each other, English first: the English rows equal --stream english's output and the translated rows --stream translated's, row for row. --on-duplicate-document and --collapse-duplicate-mentions apply within a stream. GKG 1.0 has no translated stream in gdeltforge, so v1 and v1-counts stay English.

gdeltforge crossref --events sample.parquet --gkg-version v2 --stream both --out enriched.parquet
gdeltforge sample --dataset events --mode filtered --filter '{"ActionGeo_CountryCode": ["US"]}' -n 2000 --out us_events.parquet
gdeltforge crossref --events us_events.parquet --gkg-version v2 --out us_events_enriched.parquet

Restricting GKG-side output with --columns accepts either the raw source name or the prefixed name the column actually ends up with:

gdeltforge crossref --events us_events.parquet --gkg-version v2 --columns V1THEMES GKG_V1.5TONE --out us_events_themes_tone.parquet

V1THEMES and GKG_V1.5TONE above resolve to the same underlying columns as the raw config["columns"]["gdelt_gkg_v2"] and the prefixed GKG_V1.5TONE output name would, respectively; mixing the two conventions in one --columns call is fine.

For a sample spanning the 2013-2015 window specifically (see Recipes for the full worked example):

gdeltforge sample --dataset events --mode filtered --filter '{"DATEADDED": {"op": "between", "min": 20130101, "max": 20160101}}' -n 5000 --out gap_events.parquet
gdeltforge crossref --events gap_events.parquet --gkg-version auto --out gap_events_enriched.parquet

gdeltforge codes

Looks up valid codes for GDELT's CAMEO-coded actor, geo, and event columns, so a filter value can be checked before running a sample. Needs no config file: it's a static reference lookup, usable before settings.yaml even exists.

Covers seven code families, each with its own reference list:

Family Columns
CAMEO actor-country (3-letter) Actor1CountryCode, Actor2CountryCode
FIPS geo-country (2-letter) ActionGeo_CountryCode, Actor1Geo_CountryCode, Actor2Geo_CountryCode
CAMEO ethnic Actor1EthnicCode, Actor2EthnicCode
CAMEO known-group (IGOs, NGOs, and similar organizations) Actor1KnownGroupCode, Actor2KnownGroupCode
CAMEO religion Actor1Religion1Code, Actor1Religion2Code, Actor2Religion1Code, Actor2Religion2Code
CAMEO actor-type Actor1Type1Code, Actor1Type2Code, Actor1Type3Code, Actor2Type1Code, Actor2Type2Code, Actor2Type3Code
CAMEO event (2-digit root, 3-digit base, up to 4-digit fully specified) EventCode, EventBaseCode, EventRootCode

FIPS 10-4 country codes are a different scheme from CAMEO's own 3-letter actor-country codes (UK not GBR, RS not RUS), so a value valid on one family can be silently wrong on another; gdeltforge codes <column> disambiguates before you run a sample.

Ethnic codes are listed lowercase (kur, pal), the way GDELT writes them in the Events data; every other family is uppercase. Matching ignores case everywhere: --search, sample's unrecognized-code warning, and gdeltforge.sampling.cameo_codes.lookup(column, code) for translating codes in your own code.

Three real EventCode/EventBaseCode/EventRootCode values aren't CAMEO event categories, and gdeltforge codes lists them with what they mean. --- (with -- as its root) is the CAMEO null code: the coder matched a verb pattern marked as generating no event, yet the row reached the output (325 rows in the 1979 to 2026 archive). X is undocumented anywhere in CAMEO or its coder; its 9 rows are all QuadClass 4, material conflict, with no Goldstein score. Filter these out, not in, for most analyses.

Where the tables depart from GDELT's lookup files

GDELT publishes a lookup file for each code family (gdeltproject.org/data/lookups), and the bundled tables hold every code in them. Where a file's name for a code contradicts the Events record, the bundled name follows the record: the actor names GDELT coded with an actor code, or the name GDELT wrote for a country-level place (*Geo_Type 1) with a geo code. The departures below are deliberate. Don't bring the tables back in line with the lookup files for these codes.

Code GDELT's lookup file Bundled table What the Events record shows
Ethnic bod Bodo, and Tibetan on a second line Bodo Coded with the actor name BODO; bod is not Tibetan in the record
Ethnic mon Maonan, and Mongol on a second line Maonan Coded with Maonan actors; mon is not Mongol in the record
Ethnic bas Basoga Bassa (also used for Basoga and Duala) Bassa 13,275 times, Basoga 1,021, Duala 446
Ethnic moh Mohajirs, and Mohawk on a second line Mohawk (also used for Mohajirs) Mohawk 45,550 times, Mohajirs 1,603
Geo LO Czechoslovakia Slovakia Country-level places named Slovak Republic
Geo GV Equatorial Guinea Guinea Country-level places named Guinea; Equatorial Guinea is EK, as in the lookup file

Counts are over the 1979 to 2026-07 Events archive. Where one code covers several groups, the bundled name gives the main one and says which others the code is used for.

Religion SHN keeps its CAMEO meaning, Shintoism, but GDELT's coder writes it almost only for actors named ST HELENA or SAINT HELENA: a coding error in GDELT's record. Read an SHN value as Saint Helena, not as a Shinto actor.

GDELT's event-code file, CAMEO.eventcodes.txt, has a damaged Demand section (10). The CAMEO Demand codes mirror Express intent to cooperate (03) code for code, and the subcodes in GDELT's own file still do: 1011 to 1014 match 0311 to 0314, 1051 to 1056 match 0351 to 0356. The names of the three-digit codes don't. The file calls 101 "Demand information, investigation" above subcodes for economic, military, judicial and intelligence cooperation, and 105 "Demand mediation" above subcodes for easing sanctions, releasing persons and de-escalating. The line for 1056 runs into the next code's (Demand de-escalation of military engagement106:[-5.0] Demand withdrawal), so 106 has no line of its own, and 107 and 108 read "Demand ceasefire" and "Demand meeting, negotiation". The bundled table names the Demand codes after their 03 counterparts:

Code GDELT's lookup file Bundled table Its 03 counterpart
101 Demand information, investigation Demand material cooperation, not specified below 031 material cooperation
102 Demand policy support Demand diplomatic cooperation (such as policy support) 032 diplomatic cooperation
103 Demand aid, protection, or peacekeeping Demand material aid, not specified below 033 material aid
105 Demand mediation Demand that target yields, not specified below 035 yield
106 Demand withdrawal (inside 1056's line) Demand meeting, negotiation 036 meet or negotiate
107 Demand ceasefire Demand settling of dispute 037 settle dispute
108 Demand meeting, negotiation Demand mediation 038 accept mediation

List which columns have a reference list:

gdeltforge codes

List every code for a column:

gdeltforge codes ActionGeo_CountryCode

Search within a column by name (case-insensitive substring match):

gdeltforge codes ActionGeo_CountryCode --search korea

Look up exactly what a code means:

gdeltforge codes ActionGeo_CountryCode --search IN
  IN  India

1 code(s).

A search term that exactly matches a code (case-insensitive) is treated as that lookup and returns only that one entry, even though the code also happens to be a substring of several unrelated names (Indonesia, Finland, Argentina, ...): a raw code on its own is a "what does this mean" question, not a fuzzy search, and every code in a family is unique. A search term that isn't itself a valid code falls back to the substring match above.

A term that starts with a dash, such as the event markers --- and --, has to be given as --search=---: written as --search ---, the shell argument parser reads it as another option.

Flag Description
column Positional, optional. A CAMEO/FIPS-coded column, e.g. ActionGeo_CountryCode
--search TERM An exact match (case-insensitive) against a code returns only that code; otherwise, filters results to codes or names containing this substring

Full pipeline examples

Every one of these runs the four stages in order; only the last line differs.

Sample 10,000 rows end-to-end
gdeltforge scrape --dataset events
gdeltforge convert --dataset events
gdeltforge clean --dataset events
gdeltforge sample --dataset events --mode indexed -n 10000
Reproducible sampling (fixed seed)
gdeltforge scrape --dataset events
gdeltforge convert --dataset events
gdeltforge clean --dataset events
gdeltforge sample --dataset events --mode indexed -n 5000 --seed 42
USA-only events
gdeltforge scrape --dataset events
gdeltforge convert --dataset events
gdeltforge clean --dataset events
gdeltforge sample \
    --dataset events \
    --mode filtered \
    --filter '{"ActionGeo_CountryCode": ["US"]}' \
    -n 3000
30 events per day
gdeltforge scrape --dataset events
gdeltforge convert --dataset events
gdeltforge clean --dataset events
gdeltforge sample --dataset events --mode calendar --per-period 30
Date-restricted pipeline

scrape, convert, clean, sample, and crossref each accept --start-date/--end-date independently. scrape narrows the remote listing it discovers files from; the later stages narrow which already-on-disk files they read. Passing the same range at every stage keeps the whole pipeline focused on that window, rather than scraping a narrow range and then having convert/clean/sample process every file already sitting on disk, including ones from outside it.

gdeltforge scrape --dataset events --start-date 2020-01-01 --end-date 2023-12-31
gdeltforge convert --dataset events --start-date 2020-01-01 --end-date 2023-12-31
gdeltforge clean --dataset events --start-date 2020-01-01 --end-date 2023-12-31
gdeltforge sample --dataset events --mode indexed -n 10000 --start-date 2020-01-01 --end-date 2023-12-31
Bash one-liner
gdeltforge scrape --dataset events && \
gdeltforge convert --dataset events && \
gdeltforge clean --dataset events && \
gdeltforge sample --dataset events --mode indexed -n 10000
PowerShell loop
foreach ($c in "scrape", "convert", "clean") {
    gdeltforge $c --dataset events
}
gdeltforge sample --dataset events --mode indexed -n 10000

For the complete filter syntax (nested AND/OR blocks, all operators) see Filtered Sampling; for complete runnable examples see Recipes.