Skip to main content

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.

CI PyPI version Python versions License

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 query
  • query list - List all stored queries
  • query - List all queries with last download status (shorthand for query list)
  • query remove <query_id> - Remove a query
  • query rename <query_id> --name "New Name" - Rename a query

Report Operations

  • status - Show status of all stored queries (alias for query list)
  • request <query_id> - Request a report
  • fetch <request_id> [--output filename.xml] [--poll-interval SECONDS] [--max-attempts NUM] - Fetch a requested report
  • download [--query QUERY_ID|all] [--output filename.xml] [--force] [--poll-interval SECONDS] [--max-attempts NUM] - Download reports

Prerequisites

Before using PyFlexWeb, you need to:

  1. Create a Flex Query in your IBKR Account Management portal
  2. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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:

  1. Run linting and tests
  2. Build the package
  3. Create a git tag and commit
  4. Push to GitHub and create a release
  5. 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

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

pyflexweb-0.2.3.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyflexweb-0.2.3-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

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

Hashes for pyflexweb-0.2.3.tar.gz
Algorithm Hash digest
SHA256 29db0e713d3a7bf46603abd660e6442af2f6cf66e267f68b3eece53db5684578
MD5 db3eb986889d0f2a0b67b72270f73827
BLAKE2b-256 ccb95efce5584c63e1ff2abcb80af0abee73d6aa6923a2882597c73c0f2cd7de

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflexweb-0.2.3.tar.gz:

Publisher: publish.yml on Grynn/pyflexweb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyflexweb-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d77c094f7ca6ab83b05d7ae8e2388b46bf2d3eb01cc2d87be379a6f35cdab31
MD5 1531d8a631def38b7756d769188eacd9
BLAKE2b-256 b068ba1712435398c0b334cf8ef2d4fe5423aa91f3a4fa59cafc4a02dbd8a9dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflexweb-0.2.3-py3-none-any.whl:

Publisher: publish.yml on Grynn/pyflexweb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page