Skip to main content

A Flask extension for the WooCommerce REST API.

Project description

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

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

flask_woocommerce-0.1.0rc1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

flask_woocommerce-0.1.0rc1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file flask_woocommerce-0.1.0rc1.tar.gz.

File metadata

  • Download URL: flask_woocommerce-0.1.0rc1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.19 Linux/6.12.48+deb13-cloud-amd64

File hashes

Hashes for flask_woocommerce-0.1.0rc1.tar.gz
Algorithm Hash digest
SHA256 71f9b9a1a86fd06ef144d1b46bf9c3142431e4618633910a44d9886275430ac9
MD5 0d5304ed200f01e57722750e4ed5f20a
BLAKE2b-256 2e97b3e32d8934241ee8c29e5304a9745e21e5b3efd25c96fff139f4f33e9b8b

See more details on using hashes here.

File details

Details for the file flask_woocommerce-0.1.0rc1-py3-none-any.whl.

File metadata

  • Download URL: flask_woocommerce-0.1.0rc1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.10.19 Linux/6.12.48+deb13-cloud-amd64

File hashes

Hashes for flask_woocommerce-0.1.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 65dd7526996e0b33ec78eba46f4fe69d6420264ed744f2823b5b0926fe822fa5
MD5 5d2cff2496f9e86881c91ee6d75fa9c2
BLAKE2b-256 fb6373dc88998d0a08a5d77af5ab2b1c13a99780d162d3676b0811363c6ceaf9

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