A Python module to parse Shopify webhook requests, tailored for Azure Functions.
Project description
Shopify Webhook Parser
The Shopify Webhook Parser is a versatile Python module designed for efficient parsing of Shopify webhook requests. While it includes a specific implementation for Azure Functions, its architecture is flexible, allowing it to be extended and adapted to various environments and requirements.
Features
- Strategy Pattern: At the core of this module lies the Strategy pattern, enabling dynamic selection and interchangeability of parsing logic. This approach allows for the easy addition of new parsing strategies to accommodate different processing needs or webhook formats.
- Extendable for Various Environments: Initially provided with an implementation for Azure Functions, the module is structured to be easily extendable to other platforms or frameworks.
- Robust Error Handling: Incorporates comprehensive error handling to manage and log parsing exceptions, ensuring reliability and maintainability.
- Customizable Parsing Strategies: Designed to cater to a range of webhook parsing needs, from simple to complex, the module is both customizable and scalable, fitting into different project sizes and complexities.
Implementing New Parsing Strategies
To integrate new parsing strategies, adhere to these guidelines:
- Strategy Function Signature
- Implement strategies as callables conforming to the
ParseFn
type: `(Any) -> Tuple[str, bytes, dict[str, Any], str, str]``. - They should accept a webhook request and return a tuple with the online store name, request body in bytes, headers, HMAC SHA256 string, and topic.
- Implement strategies as callables conforming to the
- Error Management
- Strategies must effectively handle and log errors.
- In case of processing failure, raise a ValueError with an informative message.
- Seamless Integration Design strategies to integrate smoothly with the parse_shopify_webhook_request function, ensuring they are compatible with expected input types.
- Comprehensive Testing
- Ensure each strategy is thoroughly tested for accurate parsing of various webhook formats.
- Include validation for edge cases and error scenarios.
Installation
pip install shopifywebhookparser
Usage
To use this module in an Azure Function, import and call the parse_shopify_webhook_request function with the appropriate parsing strategy.
Example
import azure.functions as func
from shopify_webhook_parser import parse_shopify_webhook_request, azure_func_request_parse_strategy
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
onlinestore_name, data_bytes, headers, hmac_sha256 = parse_shopify_webhook_request(
req, azure_func_request_parse_strategy
)
# Further processing of the parsed data
return func.HttpResponse(f"Processed webhook for store: {onlinestore_name}", status_code=200)
except ValueError as e:
return func.HttpResponse(f"Error: {e}", status_code=400)
Development and Contributions
Feel free to contribute to the improvement of this module by submitting pull requests or reporting issues.
Logging
The module uses Python's built-in logging to provide insights into its operations and error conditions.
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
Hashes for shopifywebhookparser-0.1.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26b94785b75e294750060f0be1450b40837a5c2909d96fc39cb3f104dd2d8615 |
|
MD5 | cb6d307d7ae9d227c22a75d5c779a92a |
|
BLAKE2b-256 | cfa3aaad8933734f1ce62a4ceebe7a9a09f073476bbb10f99f5672b4ab099ed2 |
Hashes for shopifywebhookparser-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4b8485de31305a675fa096cb4a06cccb44fbebfaaf481b7409f4887a7c417d3 |
|
MD5 | 5dd12e169c0730f0d98fb16da2ac2024 |
|
BLAKE2b-256 | d5c44bf6b36bcc7fb37b6b42c31ffdb3057978bcbf12e9ccb34ae8493f884e4c |