A Flask extension for the WooCommerce REST API.
Project description
Flask-WooCommerce
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
Release history Release notifications | RSS feed
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 flask_woocommerce-0.1.0.tar.gz.
File metadata
- Download URL: flask_woocommerce-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a378d61efb096c0042de6f73f625d1f49664a52c0264547d097d98f7ab40b71f
|
|
| MD5 |
c5ece6afac544c7c336d9f8005e78656
|
|
| BLAKE2b-256 |
947cc82d4260ee3edeee556133086a06ee3cb60c59664a701845583df2438254
|
File details
Details for the file flask_woocommerce-0.1.0-py3-none-any.whl.
File metadata
- Download URL: flask_woocommerce-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.6 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6ebf706ad8cd9fd3b29f0df4e516f8a23538bd128c0aad16f62621696fa6f0a
|
|
| MD5 |
d81d9d3420068134f95f854f886bb3b4
|
|
| BLAKE2b-256 |
7734b53c38065ad50316788feca38aca1a79ac6ce8f8179f02200a67ca2e3b75
|