A Flask extension for the WooCommerce REST API.
Find a file
Quentin Boudinel 1cbaa4a189
All checks were successful
Release and Publish / release (push) Successful in 35s
ci: separate build step from semantic-release
Add dedicated build step using poetry build and use --skip-build flag
for semantic-release to avoid redundant builds.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 11:32:52 +01:00
.forgejo/workflows ci: separate build step from semantic-release 2026-02-04 11:32:52 +01:00
.vscode feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
example feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
src/flask_woocommerce feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
tests feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
.gitignore feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
.pre-commit-config.yaml feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
CHANGELOG.md 0.1.0-rc.1 2026-02-02 22:22:03 +00:00
CONTRIBUTING.md feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
LICENSE feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
poetry.lock feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
poetry.toml feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00
pyproject.toml 0.1.0-rc.1 2026-02-02 22:22:03 +00:00
README.md feat: initial Flask-WooCommerce extension implementation 2026-02-02 23:21:15 +01:00

Flask-WooCommerce

CI Python Version License Code style: ruff

A Flask extension that integrates the WooCommerce REST API into your application.

Installation

pip install flask-woocommerce

Usage

Configuration

Add your WooCommerce credentials to the Flask app config:

app.config["WOOCOMMERCE"] = {
    "url": "https://your-store.com",
    "consumer_key": "ck_...",
    "consumer_secret": "cs_...",
}

Optional settings

Key Type Description
wp_api bool Enable the WP REST API integration
version str API version (e.g. wc/v3)
timeout float Request timeout in seconds
verify_ssl bool Verify SSL certificates
query_string_auth bool Use query string auth instead of HTTP Basic
user_agent str Custom User-Agent header value

Initialisation

Eager:

from flask import Flask
from flask_woocommerce import WooCommerce

app = Flask(__name__)
app.config["WOOCOMMERCE"] = { ... }
wc = WooCommerce(app)

Deferred (application factory pattern):

wc = WooCommerce()

def create_app():
    app = Flask(__name__)
    app.config["WOOCOMMERCE"] = { ... }
    wc.init_app(app)
    return app

Making requests

Access the underlying API client via the client property:

# Get all products
response = wc.client.get("products")

# Create a product
response = wc.client.post("products", {"name": "New Product", "regular_price": "9.99"})

# Update a product
response = wc.client.put("products/123", {"regular_price": "12.99"})

# Delete a product
response = wc.client.delete("products/123")

Multiple stores

To connect to more than one WooCommerce store, use a dict-of-dicts config:

app.config["WOOCOMMERCE"] = {
    "default": {
        "url": "https://main-store.com",
        "consumer_key": "ck_...",
        "consumer_secret": "cs_...",
    },
    "wholesale": {
        "url": "https://wholesale-store.com",
        "consumer_key": "ck_...",
        "consumer_secret": "cs_...",
    },
}

wc = WooCommerce(app)

# Access clients by name
main_products = wc.client.get("products")           # "default" client
wholesale_products = wc.clients["wholesale"].get("products")

Logging

Flask-WooCommerce uses Python's standard logging module to provide visibility into extension initialization and configuration. This can be helpful for debugging configuration issues.

Enable debug logging to see detailed information:

import logging

# Enable debug logging for Flask-WooCommerce
logging.getLogger('flask_woocommerce').setLevel(logging.DEBUG)

# Or configure via Flask's logging
app.logger.setLevel(logging.DEBUG)

Log levels used:

  • DEBUG: Configuration validation, client creation details
  • INFO: Extension initialization summary
  • ERROR: Configuration errors with full traceback

Security note: Sensitive credentials (consumer_key, consumer_secret) are automatically masked in debug logs.

Example Application

A complete example application is available in the example/ directory. It demonstrates:

  • Basic setup and configuration
  • Making API requests
  • Error handling
  • Multiple endpoint examples

See example/README.md for setup instructions.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT