Download IBKR Flex reports using the Interactive Brokers flex web service
Project description
PyFlexWeb
A command-line tool for downloading IBKR Flex reports using the Interactive Brokers flex web service.
Features
- Store and manage your IBKR Flex Web Service token securely
- Manage multiple query IDs with descriptive names
- Download activity reports and trade confirmations
- Automatic handling of request/response workflow
- Track download history to avoid unnecessary downloads
- Batch download all reports that need updating
Installation
Install:
# Install via uv (recommended)
uv tool install pyflexweb
# Or using pip
pip install pyflexweb
For development installation:
# Clone the repository
git clone https://github.com/grynn/pyflexweb.git
cd pyflexweb
# Install in development mode
uv tool install -e . # or pip install -e .
Usage
Basic Setup
First, set up your IBKR Flex Web Service token (see IBKR Flex Web Service token documentation for token generation):
pyflexweb token set YOUR_TOKEN_HERE
Add query IDs for your reports:
# Add a flex query
pyflexweb query add 123456 --name "Daily activity report"
# Add another query
pyflexweb query add 789012 --name "Trade confirmations"
Listing Queries
To see all your stored queries with their last download status:
pyflexweb query
# or
pyflexweb status
Downloading Reports
Download all reports that haven't been updated in the last 24 hours:
pyflexweb download
Download a specific report:
pyflexweb download --query 123456
Force download even if the report was already downloaded today:
pyflexweb download --query 123456 --force
Advanced Usage
For more control, you can use the two-step process:
# Request a report
request_id=$(pyflexweb request 123456)
# Fetch it later
pyflexweb fetch $request_id --output my_report.xml
Scripting Example
#!/bin/bash
# Daily report download script
# Request activity report
request_id=$(pyflexweb request 123456)
if [ $? -ne 0 ]; then
echo "Failed to request report" >&2
exit 1
fi
# Download the report
pyflexweb fetch $request_id --output "activity_$(date +%Y%m%d).xml"
Download Multiple Reports
#!/bin/bash
# Download all configured reports
# Get list of query IDs
queries=$(pyflexweb query list | tail -n +3 | awk '{print $1}')
for query in $queries; do
echo "Downloading report for query $query..."
pyflexweb download --query $query
done
Other Commands
Check version information:
pyflexweb --version
Get help on any command:
pyflexweb --help
License
This project is licensed under the terms of the GNU General Public License v3.0 or later. See the LICENSE file for details.
Command Reference
Token Management
token set <token_value>- Store your IBKR token (see IBKR Flex Web Service token documentation for token generation)token get- Display your stored token (masked for security)token unset- Remove your stored token
Query Management
query add <query_id> --name "Query Name"- Add a queryquery list- List all stored queriesquery- List all queries with last download status (shorthand forquery list)query remove <query_id>- Remove a queryquery rename <query_id> --name "New Name"- Rename a query
Report Operations
status- Show status of all stored queries (alias forquery list)request <query_id>- Request a reportfetch <request_id> [--output filename.xml] [--poll-interval SECONDS] [--max-attempts NUM]- Fetch a requested reportdownload [--query QUERY_ID|all] [--output filename.xml] [--force] [--poll-interval SECONDS] [--max-attempts NUM]- Download reports
Prerequisites
Before using PyFlexWeb, you need to:
- Create a Flex Query in your IBKR Account Management portal
- Generate a Flex Web Service token
For detailed instructions, see IBKR Flex Web Service token documentation.
Report Types
IBKR Flex reports provide data including:
- Total equity
- Open positions
- Trades
- Cash transactions
- Account statement information
The specific content depends on how you've configured your Flex Query in the IBKR Account Management portal.
Data Storage
PyFlexWeb stores its data in a SQLite database located in your user data directory:
- Windows:
C:\Users\<username>\AppData\Local\pyflexweb\pyflexweb - macOS:
~/Library/Application Support/pyflexweb - Linux:
~/.local/share/pyflexweb
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
If you want to contribute to the project or modify the code:
# Clone the repository
git clone https://github.com/grynn/pyflexweb.git
cd pyflexweb
# Install development dependencies using uv
uv sync --all-extras
# Install pre-commit hooks
uv run pre-commit install
# Run tests
uv run pytest
# Run linting and formatting
make lint
# or manually:
uv run pre-commit run --all-files
Releasing
This project uses automated PyPI publishing via GitHub Actions. To create a release:
# Bump version (choose one)
make bump-patch # 0.1.1 -> 0.1.2
make bump-minor # 0.1.1 -> 0.2.0
make bump-major # 0.1.1 -> 1.0.0
# Create GitHub release (automatically publishes to PyPI)
make release
The release process will:
- Run linting and tests
- Build the package
- Create a git tag and commit
- Push to GitHub and create a release
- Automatically publish to PyPI via GitHub Actions
For initial PyPI setup, run make setup-pypi for detailed instructions.
Code Quality
This project uses pre-commit hooks to ensure code quality:
- ruff: Fast Python linter and formatter (handles both linting and formatting)
- Standard hooks: trailing whitespace, end-of-file fixes, etc.
The pre-commit hooks will run automatically on each commit. You can also run them manually:
# Run all pre-commit hooks
make pre-commit-run
# Run just ruff linting
uv run ruff check --fix .
# Run just ruff formatting
uv run ruff format .
Acknowledgments
- Interactive Brokers for providing the Flex Web Service
- platformdirs for cross-platform data directory support
- requests for simplified HTTP handling
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyflexweb-0.2.3.tar.gz.
File metadata
- Download URL: pyflexweb-0.2.3.tar.gz
- Upload date:
- Size: 35.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29db0e713d3a7bf46603abd660e6442af2f6cf66e267f68b3eece53db5684578
|
|
| MD5 |
db3eb986889d0f2a0b67b72270f73827
|
|
| BLAKE2b-256 |
ccb95efce5584c63e1ff2abcb80af0abee73d6aa6923a2882597c73c0f2cd7de
|
Provenance
The following attestation bundles were made for pyflexweb-0.2.3.tar.gz:
Publisher:
publish.yml on Grynn/pyflexweb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyflexweb-0.2.3.tar.gz -
Subject digest:
29db0e713d3a7bf46603abd660e6442af2f6cf66e267f68b3eece53db5684578 - Sigstore transparency entry: 621686310
- Sigstore integration time:
-
Permalink:
Grynn/pyflexweb@ea94cef63037feb7842fbe170629174c6219077b -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/Grynn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea94cef63037feb7842fbe170629174c6219077b -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyflexweb-0.2.3-py3-none-any.whl.
File metadata
- Download URL: pyflexweb-0.2.3-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d77c094f7ca6ab83b05d7ae8e2388b46bf2d3eb01cc2d87be379a6f35cdab31
|
|
| MD5 |
1531d8a631def38b7756d769188eacd9
|
|
| BLAKE2b-256 |
b068ba1712435398c0b334cf8ef2d4fe5423aa91f3a4fa59cafc4a02dbd8a9dc
|
Provenance
The following attestation bundles were made for pyflexweb-0.2.3-py3-none-any.whl:
Publisher:
publish.yml on Grynn/pyflexweb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyflexweb-0.2.3-py3-none-any.whl -
Subject digest:
2d77c094f7ca6ab83b05d7ae8e2388b46bf2d3eb01cc2d87be379a6f35cdab31 - Sigstore transparency entry: 621686311
- Sigstore integration time:
-
Permalink:
Grynn/pyflexweb@ea94cef63037feb7842fbe170629174c6219077b -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/Grynn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea94cef63037feb7842fbe170629174c6219077b -
Trigger Event:
release
-
Statement type: