A collection of utilities for working with Privy, starting with a user export tool that exports all users from a Privy application to a CSV file. It includes rate limiting and automatic retries to handle API limitations gracefully.
- Exports all Privy users to a CSV file
- Handles pagination automatically
- Implements rate limiting to avoid API throttling
- Supports resuming from where it left off if interrupted
- Configurable output files
- Incremental export mode to only fetch new users since last run
- PM2 integration for scheduled runs and process management
- Duplicate detection to avoid adding the same user multiple times
- Clone this repository
- Install dependencies:
npm install - Create a
.envfile with your Privy credentials (see.env.examplefor reference)
Configure the script using environment variables in your .env file:
| Variable | Description | Default |
|---|---|---|
PRIVY_APP_ID |
Your Privy App ID | (required) |
PRIVY_APP_SECRET |
Your Privy App Secret | (required) |
OUTPUT_FILE |
Path to the output CSV file | users.csv |
CURSOR_FILE |
Path to the cursor state file | privy_cursor.txt |
TIMESTAMP_FILE |
Path to the timestamp state file | last_fetch_timestamp.txt |
FETCH_NEW_ONLY |
Only fetch users created since last run | false |
UNIQUE_FILES |
Add timestamp to output filename | false |
Run the script with:
npm run start:dev
The script will:
- Export all users from your Privy application to a CSV file
- Apply rate limiting to avoid hitting API limits
- Save progress as it runs, allowing you to resume if interrupted
This utility includes PM2 configuration for better process management:
# Start the export process
npm run pm2:start
# Check status
npm run pm2:status
# View logs
npm run pm2:logs
# Stop the process
npm run pm2:stop
# Restart the process
npm run pm2:restart
# Remove from PM2
npm run pm2:delete
The PM2 configuration automatically enables incremental mode (FETCH_NEW_ONLY=true) and unique filenames (UNIQUE_FILES=true).
The generated CSV file contains the following columns:
id: Privy user IDcreatedAt: User creation timestampisGuest: Whether the user is a guestemail: User's email address (if available)wallet: User's wallet address (if available)linkedAccounts: Number of linked accounts
The tool implements several strategies to handle Privy API rate limits:
- Respects the 30 requests per minute limit
- Implements exponential backoff with jitter for 429 responses
- Takes periodic breaks after processing batches of users
- Automatically retries on network errors
- Build the TypeScript code:
npm run build - Run in development mode:
npm run start:dev - Watch mode for development:
npm run dev - Clean build artifacts:
npm run clean