Skip to main content

Python wrapper for the Knuspr.de grocery delivery API

Project description

knuspr-api

PyPI Python License

Unofficial Python wrapper for the Knuspr.de grocery delivery API. Search products, manage your cart, check delivery slots, and view orders — from Python or the command line.

Note: Knuspr is the German brand of the Rohlik Group, which also operates Rohlik.cz, Gurkerl.at, Kifli.hu, and Sezamo.ro. This library targets the German Knuspr.de endpoint.

Features

  • Product search with automatic promoted-item filtering
  • Cart management — add items, view cart, remove by order field ID
  • Delivery slots — check available time windows
  • Order history — list past orders and view details
  • Upcoming orders — see scheduled deliveries
  • Premium info — check subscription status
  • Account data — aggregated view of your account
  • CLI with 8 commands and rich terminal output
  • Cookie-based auth with automatic login/logout via context manager
  • Rate limiting — configurable minimum interval between requests (default 100ms)
  • Pydantic v2 models with full type annotations (PEP 561)

Installation

From PyPI:

pip install knuspr-api

With uv:

uv add knuspr-api

From source:

git clone https://github.com/kegelmeier/knuspr-api.git
cd knuspr-api
uv pip install -e ".[dev]"

Quick Start

Set your Knuspr.de credentials:

export KNUSPR_USERNAME="your_email@example.com"
export KNUSPR_PASSWORD="your_password"

Or create a .env file (see .env.example).

from knuspr import KnusprClient

with KnusprClient() as client:
    # Search for products
    products = client.search_products("Bio Vollmilch", limit=5)
    for p in products:
        print(f"{p.name} - {p.price_value:.2f} EUR")

    # Add the first result to your cart
    client.add_to_cart(products[0].id, quantity=2)

    # Check your cart
    cart = client.get_cart()
    print(f"Cart: {cart.total_price:.2f} EUR ({cart.total_items} items)")

Configuration

All settings can be provided via environment variables (prefix KNUSPR_) or a .env file:

Variable Default Description
KNUSPR_USERNAME (required) Your Knuspr.de email
KNUSPR_PASSWORD (required) Your Knuspr.de password
KNUSPR_BASE_URL https://www.knuspr.de API base URL
KNUSPR_MIN_REQUEST_INTERVAL 0.1 Minimum seconds between requests
KNUSPR_REQUEST_TIMEOUT 10.0 HTTP request timeout in seconds
KNUSPR_DEBUG false Enable debug mode

You can also pass credentials directly:

with KnusprClient(username="me@example.com", password="secret") as client:
    ...

CLI Reference

The knuspr command provides 8 subcommands with rich terminal output:

# Search products
knuspr search "Hafermilch" --limit 5

# Add a product to your cart (by product ID)
knuspr add 12345 --quantity 3

# View your cart
knuspr cart

# Remove an item from your cart (by order field ID from cart output)
knuspr remove <order_field_id>

# Check delivery time slots
knuspr slots

# View order history
knuspr orders --limit 10

# View a specific order's details
knuspr order <order_id>

# View account overview
knuspr account

Python API

KnusprClient

Use as a context manager for automatic login and logout:

with KnusprClient() as client:
    ...

Methods

Method Returns Description
search_products(query, limit=10) list[SearchResult] Search for products
add_to_cart(product_id, quantity=1) int Add a product to the cart
get_cart() Cart Get current cart contents
remove_from_cart(order_field_id) bool Remove an item by its order field ID
get_delivery_slots() list[DeliverySlot] Get available delivery windows
get_order_history(limit=50, offset=0) list[Order] Get past delivered orders
get_order_detail(order_id) Order Get details for a specific order
get_upcoming_orders() list[Order] Get scheduled upcoming orders
get_premium_info() PremiumProfile Get premium subscription info
get_account_data() AccountData Get aggregated account overview

Models

All models use Pydantic v2 with extra="allow" to handle unexpected API fields gracefully.

  • SearchResult — Product from search: id, name, price_value, brand, amount, in_stock, image_path
  • Cart — Cart state: total_price, total_items, can_make_order, items
  • CartItem — Item in cart: order_field_id, product_id, product_name, quantity, price, brand
  • Order — Order summary: id, status, created_at, total_price, all_products
  • OrderProduct — Product within an order: product_id, display_name, quantity, price
  • DeliverySlot — Time window: id, start, end, is_available, price
  • PremiumProfile — Subscription: is_premium, valid_until
  • AccountData — Aggregated: user_id, address_id, premium, cart

Exceptions

from knuspr import KnusprError, AuthenticationError, RateLimitError, APIError, NetworkError
Exception When
KnusprError Base exception for all errors
AuthenticationError Login failed or session expired
RateLimitError HTTP 429 — too many requests
APIError API returned an error status
NetworkError Connection or timeout failure

Disclaimer

This is an unofficial library using reverse-engineered API endpoints. It is not affiliated with, endorsed by, or connected to Rohlik Group or Knuspr GmbH in any way.

  • The API may change without notice, which could break this library.
  • Use at your own risk and for personal use only.
  • Please respect Knuspr's terms of service and rate limits.

Contributing

# Install dev dependencies
uv pip install -e ".[dev]"

# Run tests
pytest

# Run linter
ruff check src/ tests/

# Run type checker
mypy src/

License

MIT License. See LICENSE for details.

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

knuspr_api-0.1.0.tar.gz (43.9 kB view details)

Uploaded Source

Built Distribution

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

knuspr_api-0.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file knuspr_api-0.1.0.tar.gz.

File metadata

  • Download URL: knuspr_api-0.1.0.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for knuspr_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e6727340ea57cbda6ae5d01a6f79a38f7c2cd19bac7394b4d3f4f283111fc0df
MD5 904b6081f55b1a36351c89fc6f8336da
BLAKE2b-256 d34fb4f50fdc18102d70ee3c2964ef5f9123d2b7f4d4568075e48ec5c0eb50cf

See more details on using hashes here.

File details

Details for the file knuspr_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: knuspr_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for knuspr_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d3fac764e8db660960864d97a1e3dee7129ab9c7ef6db86f6a44c2108c1a75c
MD5 2f40727aa6f0aaa267451d150222843e
BLAKE2b-256 ff2da0fbeb136b25777cb82877f8d0c90f7834e651d17090b94fc54375530032

See more details on using hashes here.

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