A Python script that downloads your backups from the Firestream API and turns them into CSV files, gzipped
like the originals (.csv.gz). It calls the same
/backups and /symbols/backups
endpoints you download from, with your own login, so the CSV holds exactly what is in your download. It can
also flatten backup files you already downloaded.
messages, activitysymbols_likes, symbols_messages,
symbols_pageviews, symbols_watchlist
flatten_backups.py (the script), README.md (setup, options and file format) and
test_flatten_backups.py (its tests). One Python file, standard library only: nothing to install.
The script can be used in two ways:
| Use | Login (username and password) | Internet |
|---|---|---|
| 2. Download and flatten in one step | Needed | Needed |
| 3. Flatten files you already downloaded | Not needed | Not needed |
For both:
python3 --version. macOS and most Linux
systems already have it. On Windows, install it from
python.org and use py instead of
python3.flatten-backups folder..csv.gz is about 35-70% of the size of the
download:| Backup | Download | .csv.gz | plain .csv |
|---|---|---|---|
| one weekday of messages (1 December 2026) | 32.5 MB | 11.8 MB | 36.1 MB |
| one weekday of symbol pageviews (1 December 2026) | 280 MB | 191 MB | 799 MB |
| one month of messages (October 2026) | 790 MB | 285 MB | 872 MB |
Login needed
The script downloads the backups from the Firestream API with your login and flattens each file as it
arrives. The download itself is not stored unless you add --keep.
You need:
https://firestream.stocktwits.com.Environment variables, on macOS or Linux:
export FIREHOSE_USER=your_user export FIREHOSE_PASS=your_password
On Windows (PowerShell):
$env:FIREHOSE_USER="your_user" $env:FIREHOSE_PASS="your_password"
Or a private file, for example ~/firehose.env (chmod 600 ~/firehose.env), passed with
--creds ~/firehose.env:
FIREHOSE_USER=your_user FIREHOSE_PASS=your_password
# one day, user and symbol streams python3 flatten_backups.py --type messages,activity,symbols_likes --from 2026-11-22 --out flat_out # a range of days (one file per type per day) python3 flatten_backups.py --type symbols_watchlist --from 2026-11-01 --to 2026-11-07 --out flat_out # monthly files: give the month as YYYY-MM python3 flatten_backups.py --type messages --from 2026-10 --out flat_out # login from a file, keep the original downloads, plain .csv instead of .csv.gz python3 flatten_backups.py --creds ~/firehose.env --type messages --from 2026-11-22 --keep originals --no-gzip
| Option | Default | Description |
|---|---|---|
--type | Types to download, comma separated:
messages, activity, symbols_likes, symbols_messages,
symbols_pageviews, symbols_watchlist | |
--from, --to | --to = --from |
Days as YYYY-MM-DD for daily files, or months as YYYY-MM for monthly files.
Both in the same format. |
--out | current folder | Folder for the flat files (created if missing). |
--no-gzip | Write plain .csv instead of .csv.gz. | |
--keep | Also save each original download (.gz) in this
folder, so you can flatten it again later without downloading it. | |
--creds | environment | File with FIREHOSE_USER= and
FIREHOSE_PASS= lines. |
--host | https://firestream.stocktwits.com | Firestream API host. |
Each type and date is one API request, the same as downloading the file with curl. A monthly file exists once the month is over, a daily file the day after.
| Command | Request |
|---|---|
--type messages --from 2026-11-22 | GET /backups/messages/2026/11/22 |
--type activity --from 2026-10 | GET /backups/activity/2026/10 |
--type symbols_likes --from 2026-11-22 | GET /symbols/backups/likes/2026/11/22 |
No login needed
If you already have backup files, for example from curl or from --keep, give them to the script
directly. It only reads the files on your disk: no username, no password and no internet access needed.
# one file python3 flatten_backups.py --out flat_out stocktwits_messages_2026_11_22.gz # several files python3 flatten_backups.py --out flat_out stocktwits_messages_2026_11_22.gz stocktwits_activity_2026_11_22.gz # every backup in a folder (macOS and Linux) python3 flatten_backups.py --out flat_out originals/*.gz
.gz, as the API sends them, or already unzipped (JSON lines).stocktwits_messages_2026_11_22.gz gives
stocktwits_messages_2026_11_22.csv.gz. Keep the name the API gives the file, so the flat file
gets the same name.--out and --no-gzip apply here. --type, --from,
--to, --keep, --creds and --host are for downloading,
so a run either downloads or flattens local files, not both.Each file logs one line when it is done. lines and rows should match:
2026/11/23 09:00:00 INFO flattened file=https://firestream.stocktwits.com/backups/messages/2026/11/22 lines=27748 messages="27748 rows -> flat_out/stocktwits_messages_2026_11_22.csv.gz"
When there are any, the log also counts:
empty_lines | Lines with no data (not written). |
invalid_lines | Lines that are not valid JSON, or events the script does not cover, such as sentiment (not written). |
lines_with_invalid_utf8 | Lines with bytes that are not UTF-8 (written, each bad byte as U+FFFD). |
A file that fails is skipped with an error, the other files still run, and the script exits with code 1 at the end (2 for wrong options).
| 401 | When downloading: wrong login, no download access for this type, or a date before your backups start. |
| 404 | When downloading: no backup file for that date yet. |
No flat file is left behind for a failed download (files are written as .part and renamed when
complete), and a failed re-run keeps the flat files of the earlier run. A backup with no events gives a flat
file with only the header row, so every date you asked for has a file.
One backup file gives one flat file with the same name: stocktwits_messages_2026_11_22.gz gives
stocktwits_messages_2026_11_22.csv.gz. Each JSON line gives one row, in the same order.
| Flat file | One row per | Columns |
|---|---|---|
stocktwits_symbols_{likes|messages|pageviews|watchlist}_{date}.csv.gz |
symbol event | created_at, symbol_id, symbol, cusip, isin, metric, user_id, location
(user_id is empty for pageviews) |
stocktwits_activity_{date}.csv.gz |
follow, like or block event (create or destroy) | time, object, action, id, created_at, user_id, following_user_id, liked_user_id, message_id,
blocked_user_id, muted, locationtime is when the event happened; for a destroy, created_at is when the follow,
like or block was made. |
stocktwits_messages_{date}.csv.gz |
message event (create or destroy) | 45 columns:
|
\n line endings.multiLine=true), not line by line.true/false.|: mentioned_users, links,
user_classification, symbol_*. A | inside an item is written as
%7C; this only happens in links, where it is the same URL.action=destroy.
A message can tag several symbols, but it is still one row. So each symbol detail (ticker, exchange, CUSIP,
price...) is one column that lists a value for every symbol, separated by |, always in the same
order. The position links the values: the 1st item of every symbol_* column is about the 1st
symbol, the 2nd item about the 2nd symbol, and so on.
For example, a message that tags $INDA, $SPX and $NDX has symbol_count = 3 and:
| Column | Cell | 1st symbol | 2nd symbol | 3rd symbol |
|---|---|---|---|---|
symbols | INDA|SPX|NDX | INDA | SPX | NDX |
symbol_exchanges | BATS|INDEX|INDEX | BATS | INDEX | INDEX |
symbol_cusips | 46429B598|| | 46429B598 | (none) | (none) |
symbol_prices | 52.89|6910.39| | 52.89 | 6910.39 | (none) |
When a symbol has no value, its slot is left empty but kept, so the positions still line up. Here SPX and NDX
are indexes and have no CUSIP, and the message has no price for NDX: 52.89|6910.39| ends with an
empty 3rd slot. Without that slot, a reader could not tell which symbol is missing its price. A message without
symbols has symbol_count = 0 and empty symbol_* cells.
To analyze by symbol, split the lists into one row per symbol. The message above becomes:
| message_id | symbol | price |
|---|---|---|
| 123 | INDA | 52.89 |
| 123 | SPX | 6910.39 |
| 123 | NDX |
-- DuckDB (messages without symbols are left out)
SELECT message_id,
unnest(string_split(symbols, '|')) AS symbol,
unnest(string_split(symbol_prices, '|')) AS price
FROM 'stocktwits_messages_2026_11_22.csv.gz';
# pandas (messages without symbols keep one row with an empty symbol)
import pandas as pd
df = pd.read_csv("stocktwits_messages_2026_11_22.csv.gz", dtype=str, keep_default_na=False)
cols = ["symbols", "symbol_prices"]
df[cols] = df[cols].apply(lambda c: c.str.split("|"))
df.explode(cols)
The script downloads the same backup files you get from /backups and
/symbols/backups with your login, and only converts them to CSV. It does not add, drop or filter
events. If a number looks wrong, compare it with the original file: the two always agree.
stocktwits_messages_2026_11_22.gz becomes stocktwits_messages_2026_11_22.csv.gz. You
can always tell which download a CSV came from, and if one day fails you re-run only that day.
Each line of a backup file is one event, and it becomes exactly one CSV row.
lines=27748 and 27748 rows. If they match, every event made it into the CSV.action=destroy. Whether to drop it depends on your analysis, so the CSV keeps it.In the JSON, the author is nested inside the message:
{"id": 1001, "body": "...", "user": {"id": 42, "username": "alice", "followers": 150}}
In the CSV they are on one row, so you don't need a join:
| message_id | body | user_id | username | user_followers |
|---|---|---|---|---|
| 1001 | ... | 42 | alice | 150 |
The author columns show the profile at the time of that message. If alice had 100 followers on Nov 1 and 150 on Nov 22, her Nov 1 messages show 100 and her Nov 22 messages show 150.
| lists
A message can tag several symbols but stays one row, so each symbol detail lists one value per symbol, in the
same order (INDA|SPX|NDX). See Symbols of a message for how to read the
lists and split them into one row per symbol.
The script copies each value as it is in the JSON:
230.10 stays 230.10, not 230.1;1000000 stays 1000000, not 1e+06;2026-11-22T14:05:09Z);it's (HTML for "it's"), the CSV has
the same, and you decide whether to decode it.
The one change: a | inside a list item is written as %7C, so a list always splits
into one item per value. Only links ever contain a |, and for a URL | and
%7C mean the same.
Tip: read ids as text (dtype=str in pandas) so your own tools don't round them.
These are dropped to keep the CSV focused on data. They are still in the original JSON if you need them:
is_following ("does the viewer follow this user", which does not apply to a backup);media_count is kept);seq_id, which is always empty in backups..csv.gz is usually 35-70% of the download's size, and pandas,
DuckDB and Spark read it directly..part files: while a file is being written it is called
stocktwits_messages_2026_11_22.csv.gz.part, and it is renamed only when complete. A file without .part is
always complete, even if the script was stopped halfway.Sentiment backups are not covered.