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 from PyPI:

# Using 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:

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
  • 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's 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.1.3.tar.gz (33.3 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.1.3-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file pyflexweb-0.1.3.tar.gz.

File metadata

  • Download URL: pyflexweb-0.1.3.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyflexweb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 31266128ba41b3c57120af66ee8fd1b9e926a0c78fb105d2909ef1c157df4b0c
MD5 23bb4ee09442c9aad20cadcc9966547e
BLAKE2b-256 f579c504c3873a13823cd40d6d84086ab2c39f3c8fd8bb012392a92fe9fd619e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflexweb-0.1.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.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyflexweb-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyflexweb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 07a3a023e44f0115585a17cd4e8df19a0a49d90c93f2454ace4b6fb70df90ea4
MD5 1f86dbac93d2726e432117af8940813c
BLAKE2b-256 5f31814acc9da83a6848324d01c37f29e903e59848bfacde6ce0ef1e8a6bbc3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyflexweb-0.1.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