Python Script
Python Data Export
CLI tool for bulk-exporting firearms, manufacturers, calibers, or categories to CSV and JSON. Handles pagination, filtering, and output formatting.
gunspec-export.py
Requirements
# Python 3.9+ required
pip install requestsQuick Start
1
Download the file using the button above
2
Run it:
python gunspec-export.py --api-key test_key --base-url http://localhost:8787 --resource firearms --format csv3
Output: firearms.csv with all firearms, paginated automatically
CLI Options
| Flag | Default | Description |
|---|---|---|
--api-key | (required) | Your GunSpec API key |
--base-url | Auto-detected | API base URL |
--resource | firearms | firearms, manufacturers, calibers, or categories |
--format | csv | csv or json |
--output | resource.format | Output file path |
--filter | (none) | Key=value filter, repeatable |
Examples
# Export all firearms as CSV
python gunspec-export.py --api-key test_key \
--base-url http://localhost:8787 \
--resource firearms --format csv
# Export only Colt firearms as JSON
python gunspec-export.py --api-key test_key \
--base-url http://localhost:8787 \
--resource firearms --format json \
--filter manufacturer=colt-defense
# Export calibers
python gunspec-export.py --api-key test_key \
--base-url http://localhost:8787 \
--resource calibers --format csv
# Export to a specific file
python gunspec-export.py --api-key test_key \
--base-url http://localhost:8787 \
--resource manufacturers \
--output data/manufacturers.csvPagination: The script fetches 50 records per page automatically. Progress is printed to stderr so you can pipe stdout to a file or another command.


