Skip to main content

Python module for comdirect REST api

Project description

comdirect-api-wrapper

PyPI version Build Status Python uv

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.

  1. Enable API access in your Comdirect settings (https://www.comdirect.de/cms/kontakt-zugaenge-api.html).
  2. Obtain your client_id and client_secret.
  3. 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}")

# --- 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)
    with open(f"{doc.name}.pdf", "wb") as f:
        f.write(pdf_bytes)

Disclaimer

This project is not affiliated with, maintained, or endorsed by comdirect bank AG. Use this software at your own risk. The authors provide no warranty and accept no liability for any financial losses or damages resulting from the use of this software.


License: MIT

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

comdirect_api_wrapper-0.2.tar.gz (69.2 kB view details)

Uploaded Source

Built Distribution

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

comdirect_api_wrapper-0.2-py3-none-any.whl (153.4 kB view details)

Uploaded Python 3

File details

Details for the file comdirect_api_wrapper-0.2.tar.gz.

File metadata

  • Download URL: comdirect_api_wrapper-0.2.tar.gz
  • Upload date:
  • Size: 69.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comdirect_api_wrapper-0.2.tar.gz
Algorithm Hash digest
SHA256 671d8a0874a8ed8d8aebced55e2a433b40463bbe43879637bbb22095cbdb1ca0
MD5 d556bcaff327d386505477ff37cc5a1f
BLAKE2b-256 b432970c83a4d445395b8d13696a2bcfc6ca1382610dad25b5a6f35aa1c9e5ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for comdirect_api_wrapper-0.2.tar.gz:

Publisher: publish.yml on mad4ms/comdirect-api-wrapper

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

File details

Details for the file comdirect_api_wrapper-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for comdirect_api_wrapper-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8459abdab1828f032f4d349fbc114fbeb2e47fba2975e9204278396348193287
MD5 709bc8f7cbdb4f4cf72807ee96fa9cba
BLAKE2b-256 52494a38af87297446af5edb9a3d33284bb8a391252dc19d2b0de1cf0ee99abe

See more details on using hashes here.

Provenance

The following attestation bundles were made for comdirect_api_wrapper-0.2-py3-none-any.whl:

Publisher: publish.yml on mad4ms/comdirect-api-wrapper

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