Command-line interface for the beehiiv newsletter platform API
Manage your beehiiv newsletter from the terminal. Check subscriber counts, pull post stats, export lists, look up individual subscribers, and more — all without leaving your shell.
pip install bhvAfter install, bhv is available as a command.
git clone https://github.com/insightslab-ai/bhv.git
cd bhv
chmod +x bhv bhv.py
# Add to your PATH (pick one):
ln -s "$(pwd)/bhv" /usr/local/bin/bhv # system-wide
# or
echo 'export PATH="$(pwd):$PATH"' >> ~/.zshrc # current dir on PATHbhv uses the requests library if available, and falls back to Python's built-in urllib otherwise. For best results:
pip install requests- API key: beehiiv dashboard → Settings → API
- Publication ID: beehiiv dashboard → Settings → Publication → Publication ID (format:
pub_xxxxxxxxxx)
Option A — environment variables (great for CI/scripts):
export BEEHIIV_API_KEY="your_api_key_here"
export BEEHIIV_PUB_ID="pub_xxxxxxxxxxxxxxxxxx"Option B — secrets file (recommended for daily use):
mkdir -p ~/.config/beehiiv
cat > ~/.config/beehiiv/secrets.env << 'EOF'
BEEHIIV_API_KEY=your_api_key_here
BEEHIIV_PUB_ID=pub_xxxxxxxxxxxxxxxxxx
EOF
chmod 600 ~/.config/beehiiv/secrets.envbhv subscribers --count
bhv stats --days 30
bhv posts --limit 5Count subscribers by status:
bhv subscribers --count──────────────────────────────────────────────────
Subscriber Counts
──────────────────────────────────────────────────
Active 4,821
Inactive 312
Pending 47
──────────────────── ──────────
Total 5,180
──────────────────────────────────────────────────
List subscribers (default: 25 active):
bhv subscribers --list --limit 25
bhv subscribers --list --limit 100 --status inactive
bhv subscribers --list --since 2025-01-01
bhv subscribers --list --by-utm twitterExport to CSV:
bhv subscribers --export-csv subscribers.csv
bhv subscribers --export-csv active.csv --status activeFlags:
| Flag | Description | Default |
|---|---|---|
--count |
Show counts by status | — |
--list |
Show subscriber table | — |
--export-csv PATH |
Export all to CSV file | — |
--status STATUS |
Filter: active, inactive, pending, all |
active |
--limit N |
Max rows to display | 25 |
--by-utm SOURCE |
Filter by utm_source |
— |
--since YYYY-MM-DD |
Only subscribers created after date | — |
--json |
Output raw JSON | — |
bhv stats
bhv stats --days 30
bhv stats --jsonShows total subscribers, active/inactive breakdown, new subscribers in the lookback window, and estimated growth rate.
Flags:
| Flag | Description | Default |
|---|---|---|
--days N |
Lookback period for new subscriber count | 7 |
--json |
Output raw JSON | — |
bhv posts
bhv posts --limit 10
bhv posts --json
bhv posts --csv > posts.csvShows recent posts with open rates, click rates, and send counts.
Flags:
| Flag | Description | Default |
|---|---|---|
--limit N |
Number of posts to show | 10 |
--json |
Output raw JSON | — |
--csv |
Output as CSV (stdout) | — |
bhv post post_abc123def456
bhv post post_abc123def456 --jsonShows full detail for a single post: status, publish date, recipients, opens, clicks, open rate, click rate, unsubscribes.
bhv subscriber user@example.com
bhv subscriber user@example.com --jsonShows status, tags, custom fields, UTM parameters, referral count and code.
bhv segments
bhv segments --jsonLists all segments with name, type, subscriber count, and creation date.
bhv custom-fields
bhv custom-fields --jsonLists all custom fields defined on your publication.
bhv automations
bhv automations --jsonLists all automations with name, status, and trigger type.
bhv export-hashed hashes.txtExports all active subscriber emails as SHA-256 hashes (lowercase, trimmed), one per line. Use for uploading custom audiences to Meta Ads without sharing raw email addresses.
bhv looks for credentials in this order:
- Environment variables already set in the shell
(BEEHIIV_API_KEY,BEEHIIV_PUB_ID) - Default secrets file:
~/.config/beehiiv/secrets.env - Custom config file:
--config /path/to/secrets.env
# ~/.config/beehiiv/secrets.env
BEEHIIV_API_KEY=your_api_key_here
BEEHIIV_PUB_ID=pub_xxxxxxxxxxxxxxxxxxSupports # comments, quoted values, and KEY=VALUE format. Keep this file mode 600.
bhv --config /path/to/other-pub.env subscribers --countUseful for managing multiple publications.
| Flag | Description |
|---|---|
--version |
Print version and exit |
--config PATH |
Path to alternative secrets file |
All subcommands support --json to output raw API responses for piping to jq or scripting.
# Morning dashboard
bhv stats --days 7
bhv posts --limit 5
# Export for analysis
bhv subscribers --export-csv ~/Downloads/subscribers-$(date +%Y%m%d).csv
bhv posts --csv > posts.csv
# Pipe to jq
bhv posts --json | jq '[.[] | {title: .subject, opens: .stats.email.unique_opens}]'
# Upload to Meta Ads
bhv export-hashed meta-audience.txt
# Check a specific subscriber
bhv subscriber hello@example.comWhen using in scripts or CI, set credentials via environment variables:
BEEHIIV_API_KEY="..." BEEHIIV_PUB_ID="..." bhv subscribers --countOr export them before running:
export BEEHIIV_API_KEY="..."
export BEEHIIV_PUB_ID="..."
bhv stats --jsonbeehiiv API documentation: https://developers.beehiiv.com/docs/v2
MIT — see LICENSE
Built by Insights Lab