Skip to content
◉RedLens Get RedLens on GitHub
Public Discussion Analysis

Export a RedLens Archive to CSV and Check Its Contents

Export archived Reddit users or topics to CSV with RedLens. Check row counts, understand mixed fields, and choose JSON or JSONL for stored-text fidelity.

The RedLens Project

For a CSV export of an already archived Reddit account, specify the SQLite file, username, format and output path:

redlens --db research.sqlite export example_user --format csv -o example_user.csv

Replace research.sqlite with your archive path and example_user with a username stored in it. Export reads the local archive; it does not sync new Reddit activity. With -o, the command writes a UTF-8 file and reports the numbers of posts and comments written to the terminal’s error stream, keeping the CSV separate from that status message. Choose a new output filename if you need to preserve an earlier export: an existing file at that path is overwritten. These examples follow the current RedLens CLI as of October 10, 2026.

Choose a user or a tracked topic

First, inspect the intended database:

redlens --db research.sqlite list
redlens --db research.sqlite topics

list shows archived users and their post/comment counts; topics shows tracked topics, keywords and matched-post counts. Supply exactly one export scope: a username or --topic, not both. JSON is the default format, so keep --format csv explicit. CLI reference

To export an existing tracked topic named public-transit:

redlens --db research.sqlite export --topic public-transit --format csv -o public-transit.csv

The scopes answer different questions:

  • User export: posts and comments in the database authored by that account.
  • Topic export: retained matched posts plus comments already stored beneath those posts. Those comments need not independently contain the topic keywords.

Topic export honors stored relevance flags: posts explicitly marked irrelevant, and comments beneath them, are excluded; unscored posts remain included. It is therefore not necessarily an export of every raw keyword match. Export implementation and topic selection logic

If you have not collected the data yet, start with archiving a Reddit user locally. Topic collection offers track --comments to pull comment threads under matched posts; exporting alone cannot retrieve missing comments. Document the collection’s subreddit list, keywords, time window, exclusions, relevance filtering and failures rather than treating a CSV as complete Reddit coverage. Tracking options

Read the mixed table correctly

RedLens writes posts and comments into one table, distinguished by kind, whose values are post and comment. The header is the union of fields found in the exported records, with blanks where a field does not apply. Do not assume every export has identical columns: a post-only export lacks comment-only fields, and an empty export has just the kind header. CSV writer

Useful fields include:

Field Interpretation
author_username, subreddit_name Account and community recorded in the archive
created_utc Creation time as a Unix timestamp in seconds
fetched_at Local record’s fetch timestamp, also in seconds
post_id / comment_id Identifier appropriate to the row’s kind
title, selftext, url Post fields
body, link_id, parent_id Comment fields; link_id identifies the parent post and can be joined to post_id

These are the stored record fields, not an export of every field available from Reddit or its mirror. A user export does not necessarily include the parent posts for that user’s comments: its post rows are limited to posts authored by the selected account. Import identifier and text columns as text, and convert timestamps explicitly rather than expecting spreadsheet date detection.

Row order is also meaningful: user exports write chronologically ordered posts, then chronologically ordered comments—not one interleaved timeline. Topic exports write score-ranked posts, then score-ranked comments. Sort by created_utc yourself for a combined activity timeline. Export ordering and topic ordering

Check records, not physical lines

Reddit text can contain commas, quotation marks and newlines. Use a CSV parser rather than splitting on commas or counting file lines. Python’s standard-library DictReader reads the header and handles quoted fields. Python CSV documentation

Save this as check_csv.py, adjust the filename, and run python check_csv.py:

import csv
from collections import Counter

with open("example_user.csv", encoding="utf-8", newline="") as f:
    reader = csv.DictReader(f)
    print("columns:", reader.fieldnames)
    counts = Counter(row["kind"] for row in reader)

print("posts:", counts["post"])
print("comments:", counts["comment"])

Compare these counts with the export command’s status message. Keep the command, RedLens version (redlens --version), export date and collection settings alongside the file. CSV does not carry a separate username/topic scope header. CLI and export formats

Use JSON or JSONL when fidelity matters

CSV has two important transformations here:

  • Null values, empty strings and missing fields all become empty cells, losing those distinctions. Python CSV writer behavior
  • RedLens prefixes string values beginning with =, +, -, @, tab or carriage return with an apostrophe as a spreadsheet formula-injection precaution. That means some exported text differs from the stored text. CSV transformation

For analysis requiring unchanged stored strings or explicit nulls, choose JSON or JSONL instead. JSON separates posts and comments under a username/topic header; JSONL writes one kind-tagged record per line. The formula-prefix transformation applies only to CSV. Format implementation

redlens --db research.sqlite export example_user --format jsonl -o example_user.jsonl

JSONL suits line-oriented downstream processing, but the current exporter still loads the selected posts and comments into memory before writing; it is not a constant-memory database export.

Finally, CSV export has no --anon option. Usernames remain in its records. Review identifiers and free text before sharing, and retain the SQLite archive as your source dataset rather than replacing it with the CSV. Export options