Python module for comdirect REST api
Project description
comdirect-api-wrapper
A modern, type-safe Python wrapper for the comdirect REST API.
This library allows you to interact with your Comdirect bank accounts programmatically. It handles the complex OAuth2 authentication flow (including 2FA challenge-response for PhotoTAN, PushTAN, and SMS-TAN), auto-refreshes tokens, and provides a pythonic interface for retrieving balances, transactions, and depot positions.
Features
- Authentication: Full OAuth2 support with automatic token refresh and session handling.
- 2FA Support: Built-in callbacks for PhotoTAN (App), PushTAN, and SMS-TAN.
- Banking: Retrieve account lists, balances, and transaction history.
- Brokerage: Fetch depot overviews and detailed position data.
- Documents: Download postbox documents (PDFs).
- Type Safe: Fully typed domain models for great IDE support and autocompletion.
Installation
Using uv (Recommended)
uv add comdirect-api-wrapper
Using pip
pip install comdirect-api-wrapper
Quick Start
1. Prerequisites
You need user credentials AND API credentials from Comdirect.
- Enable API access in your Comdirect settings (https://www.comdirect.de/cms/kontakt-zugaenge-api.html).
- Obtain your
client_idandclient_secret. - Your smartphone with the Comdirect PhotoTAN app installed (for 2FA).
2. Configuration
python-dotenv to manage secrets. Create a .env file:
COMDIRECT_USERNAME=your_username
COMDIRECT_PASSWORD=your_password
COMDIRECT_CLIENT_ID=your_client_id
COMDIRECT_CLIENT_SECRET=your_client_secret
3. Usage Example
import os
from dotenv import load_dotenv
from comdirect_api.client import ComdirectClient
from comdirect_api.utils import default_photo_tan_callback, default_push_tan_callback
load_dotenv()
# 1. Setup Credentials
credentials = {
"username": os.getenv("COMDIRECT_USERNAME"),
"password": os.getenv("COMDIRECT_PASSWORD"),
"client_id": os.getenv("COMDIRECT_CLIENT_ID"),
"client_secret": os.getenv("COMDIRECT_CLIENT_SECRET"),
}
# 2. Setup 2FA Handlers (What happens when the bank asks for a TAN?)
tan_handlers = {
# For PhotoTAN App (Push):
"push_tan_cb": default_push_tan_callback,
# For PhotoTAN Graphic (Scan):
"photo_tan_cb": default_photo_tan_callback,
}
# 3. Initialize & Login
client = ComdirectClient(credentials, tan_handlers)
client.login() # Triggers 2FA interaction if needed
# 4. Fetch Data
# --- Accounts ---
for account in client.list_accounts():
print(f"Account: {account.id} | Balance: {account.balance} {account.currency}")
# Fetch Transactions
for tx in client.list_transactions(account.id):
print(f" {tx.booking_date}: {tx.amount} {tx.currency} - {tx.purpose}")
# # or
# transactions = list(client.iter_all_transactions(account.id))
# for tx in transactions:
# print(f" {tx.booking_date}: {tx.amount} {tx.currency} - {tx.purpose}")
# --- Depot ---
for depot in client.list_depots():
balance, positions = client.get_depot_positions(depot.id)
print(f"Depot Value: {balance.current_value} EUR")
for pos in positions:
print(f" {pos.quantity}x {pos.instrument_name} ({pos.wkn})")
Advanced Usage
Pagination
For accounts with many transactions, use the iterator which handles pagination automatically:
for tx in client.iter_all_transactions(account_id):
# This automatically fetches pages as you iterate
process_transaction(tx)
Document Retrieval
docs = client.list_documents()
for doc in docs:
print(f"Downloading {doc.name}...")
pdf_bytes = client.download_document(doc.id, doc.mime_type)
with open(f"{doc.name}.pdf", "wb") as f:
f.write(pdf_bytes)
Model Context Protocol (MCP) Server
This library includes a fully functional Model Context Protocol (MCP) server. This allows AI assistants (like Claude Desktop) to connect directly to your Comdirect accounts to fetch balances, search transactions, and analyze your portfolio.
See MCP_USAGE.md for setup and usage instructions.
Quick Config for Claude Desktop
{
"mcpServers": {
"comdirect": {
"command": "python",
"args": ["/absolute/path/to/comdirect-api-wrapper/mcp_server.py"],
"env": {
"COMDIRECT_CLIENT_ID": "...",
"COMDIRECT_CLIENT_SECRET": "...",
"COMDIRECT_USERNAME": "...",
"COMDIRECT_PASSWORD": "..."
}
}
}
}
Disclaimer
This project is not affiliated with, maintained, or endorsed by the comdirect bank. Use this software at your own risk. I provide no warranty and accept no liability for any financial losses or damages resulting from the use of this software.
This project is designed to run locally and does not collect, store, or transmit your banking credentials to any third parties.
Nevertheless, be cautious and review the code before use, especially when dealing with sensitive financial data.
License: MIT
Development
Pre-commit Hooks
This project uses pre-commit to ensure code quality and prevent accidental secret commits.
- Install pre-commit:
uv pip install pre-commit
- Install the git hooks:
pre-commit install
Now, checks (formatting, linting, secret scanning) will run automatically before every commit.
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 comdirect_api_wrapper-0.3.tar.gz.
File metadata
- Download URL: comdirect_api_wrapper-0.3.tar.gz
- Upload date:
- Size: 73.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f87ff06dce00c5797610eb0a950e2b8fc7458150c7ab6326026cec5a4273131
|
|
| MD5 |
bcce033ed17d66c71fa18d9c229bae91
|
|
| BLAKE2b-256 |
ff349188f980f94217dda730e9cae3b9d6a488ac82940d88c87a22daaefc0cad
|
Provenance
The following attestation bundles were made for comdirect_api_wrapper-0.3.tar.gz:
Publisher:
publish.yml on mad4ms/comdirect-api-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
comdirect_api_wrapper-0.3.tar.gz -
Subject digest:
6f87ff06dce00c5797610eb0a950e2b8fc7458150c7ab6326026cec5a4273131 - Sigstore transparency entry: 850022057
- Sigstore integration time:
-
Permalink:
mad4ms/comdirect-api-wrapper@1ad3bfb9e30a6304a02b4deee2f37f183cabf82e -
Branch / Tag:
refs/tags/v0.3 - Owner: https://github.com/mad4ms
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1ad3bfb9e30a6304a02b4deee2f37f183cabf82e -
Trigger Event:
release
-
Statement type:
File details
Details for the file comdirect_api_wrapper-0.3-py3-none-any.whl.
File metadata
- Download URL: comdirect_api_wrapper-0.3-py3-none-any.whl
- Upload date:
- Size: 155.0 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 |
d363eb1710a71a8ed2937731292602bcafe57c39ee8468a1901593b128dc80b0
|
|
| MD5 |
b5db0882e15acc4dfc8a7200e5c86718
|
|
| BLAKE2b-256 |
7d3e744d54178b80e3bf208718fb71c123075256c288da8170a8ee458f203cf2
|
Provenance
The following attestation bundles were made for comdirect_api_wrapper-0.3-py3-none-any.whl:
Publisher:
publish.yml on mad4ms/comdirect-api-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
comdirect_api_wrapper-0.3-py3-none-any.whl -
Subject digest:
d363eb1710a71a8ed2937731292602bcafe57c39ee8468a1901593b128dc80b0 - Sigstore transparency entry: 850022058
- Sigstore integration time:
-
Permalink:
mad4ms/comdirect-api-wrapper@1ad3bfb9e30a6304a02b4deee2f37f183cabf82e -
Branch / Tag:
refs/tags/v0.3 - Owner: https://github.com/mad4ms
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1ad3bfb9e30a6304a02b4deee2f37f183cabf82e -
Trigger Event:
release
-
Statement type: