Webservice client for PrestaShop API
Project description
PrestaShop Webservice
Python client to interact with PrestaShop API in a simple and efficient way. Designed for internal company use.
Features
- ๐ Optimized HTTP client with persistent connections
- ๐พ Automatic response caching with configurable TTL
- ๐ Singleton pattern for efficient connection management
- ๐ Integrated logging with Loguru
- ๐ฏ Full type hints support
- ๐ Simple and reusable primitive queries
- ๐ฆ Type-safe parameter system
Installation
Direct installation from repository
pip install git+https://github.com/yourcompany/prestashop-webservice.git
Development mode installation
git clone https://github.com/yourcompany/prestashop-webservice.git
cd prestashop-webservice
pip install -e .
Installation with development dependencies
pip install -e ".[dev]"
Usage
Initialization
from prestashop_webservice import Client
# Create repository instance (Singleton)
repo = Client(
prestashop_base_url="https://your-store.com/api",
prestashop_ws_key="YOUR_API_KEY_HERE",
max_connections=2,
max_keepalive_connections=2,
keepalive_expiry=10.0
)
Basic queries
# Get an order by ID
order = repo.query_order(order_id="12345")
# Check if an order exists
exists = repo.exists_order(order_id="12345")
# Get an address
address = repo.query_address(address_id="67890")
# Get a customer
customer = repo.query_customer(customer_id="123")
# Get a product
product = repo.query_product(product_id="456")
# Get a country
country = repo.query_country(country_id="6")
# Get an order state
order_state = repo.query_order_state(state_id="5")
Queries with parameters
from prestashop_webservice import Params, Sort, SortOrder
# Create query parameters
params = Params(
filter={"id_customer": "123"},
sort=Sort(field="date_add", order=SortOrder.DESC),
display=["id", "total_paid", "reference"],
limit=10
)
# Get orders with filters
orders = repo.query_orders(params=params)
# Get customers with filters
customers_params = Params(
filter={"active": "1"},
display=["id", "email", "firstname", "lastname"],
limit=50
)
customers = repo.query_customers(params=customers_params)
# Get order history
history_params = Params(
filter={"id_order": "12345"},
display=["id_order_state", "date_add"]
)
histories = repo.query_order_histories(params=history_params)
# Get order carriers
carrier_params = Params(
filter={"id_order": "12345"}
)
carriers = repo.query_order_carriers(params=carrier_params)
Advanced examples
# Search customers by email
email_params = Params(
filter={"email": "customer@example.com"},
display=["id", "email"]
)
customers = repo.query_customers(params=email_params)
# Get last 20 orders sorted by date
recent_orders_params = Params(
sort=Sort(field="date_add", order=SortOrder.DESC),
display=["id", "reference", "total_paid", "date_add"],
limit=20
)
recent_orders = repo.query_orders(params=recent_orders_params)
# Search products by category
products_params = Params(
filter={"id_category_default": "5"},
display=["id", "name", "price"],
limit=100
)
products = repo.query_products(params=products_params)
API Reference
Client
Main class to interact with PrestaShop API.
Available methods
Orders
query_order(params=None, order_id="")โdictquery_orders(params=None)โlistexists_order(order_id)โbool
Customers
query_customer(params=None, customer_id="")โdictquery_customers(params=None)โlist
Addresses
query_address(params=None, address_id="")โdict
Products
query_product(params=None, product_id="")โdict
Order Carriers
query_order_carriers(params=None)โdict
Order Histories
query_order_histories(params=None)โlist
Order States
query_order_state(params=None, state_id="")โdict
Countries
query_country(params=None, country_id="")โdict
Params
Class to build query parameters in a safe and typed way.
@dataclass
class Params:
filter: dict | None # Search filters
sort: Sort | None # Sorting
display: list[str] | None # Fields to display
limit: int | None # Result limit
Sort
Class to define sorting.
@dataclass
class Sort:
field: str # Field to sort by
order: SortOrder # Sort direction (ASC/DESC)
SortOrder
Enumeration for sort order.
class SortOrder(Enum):
ASC = "ASC" # Ascending
DESC = "DESC" # Descending
Cache
All query_* methods use automatic caching:
- TTL (Time To Live): 24 hours (86400 seconds) by default
- Maximum cache size: Varies by endpoint (50-500 items)
- Parameter-based cache: Queries with different parameters are cached separately
Logger Configuration
The logger is pre-configured with:
- INFO level for console
- DEBUG level for file
- Automatic log rotation (10 MB)
- 10 days retention
- ZIP compression of old logs
- Location:
logs/app.log
Development
Run tests
pytest
Run tests with coverage
pytest --cov=prestashop_repository --cov-report=html
Format code
black .
Type checking
mypy prestashop_repository
Project structure
prestashop-webservice/
โโโ src/
โ โโโ __init__.py # Main exports
โ โโโ client.py # Main Client class
โ โโโ params.py # Parameter models
โ โโโ logger.py # Logging configuration
โ โโโ py.typed # Type checking marker
โโโ tests/ # Tests (pending)
โโโ docs/ # Additional documentation
โโโ setup.py # Installation configuration
โโโ pyproject.toml # Modern Python configuration
โโโ requirements.txt # Dependencies
โโโ MANIFEST.in # Files to include in distribution
โโโ LICENSE # MIT License
โโโ README.md # This file
License
MIT License - See LICENSE file for details.
Support
To report bugs or request new features, please open an issue on the GitHub repository.
Contributing
Contributions are welcome. Please:
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Changelog
0.1.0 (2025-11-13)
- โจ Initial release
- ๐ฏ Primitive queries for all main endpoints
- ๐พ Integrated cache system
- ๐ Logging with Loguru
- ๐ Singleton pattern
- ๐ฆ Typed parameter system
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 prestashop_webservice-0.1.0.tar.gz.
File metadata
- Download URL: prestashop_webservice-0.1.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d016a5c4397aae1a3f2fc4984eb14e55f3e5af590ce4880a13b1ab9378d044dd
|
|
| MD5 |
8ed70b5a7c2f6c9dbf005266784dc904
|
|
| BLAKE2b-256 |
749388ac99511cf04a0f3744eba9ea04c06f66c2024b84ce9063963004b9cddf
|
Provenance
The following attestation bundles were made for prestashop_webservice-0.1.0.tar.gz:
Publisher:
publish.yml on patitas-and-co/prestashop-webservice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prestashop_webservice-0.1.0.tar.gz -
Subject digest:
d016a5c4397aae1a3f2fc4984eb14e55f3e5af590ce4880a13b1ab9378d044dd - Sigstore transparency entry: 699690925
- Sigstore integration time:
-
Permalink:
patitas-and-co/prestashop-webservice@e86926b0b15e559d4276b172d593168758b808f6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/patitas-and-co
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e86926b0b15e559d4276b172d593168758b808f6 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file prestashop_webservice-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prestashop_webservice-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e529adb5b9c29190c98122d701c2e4f00c5bfd95df2dd07025301c0fe4c992f
|
|
| MD5 |
80ec3373e5ce88fbb283b30546fa137b
|
|
| BLAKE2b-256 |
02308cd769fd818415ec77029ba18c1298bb5e7891593ff5b7e2cb8d0abcb697
|
Provenance
The following attestation bundles were made for prestashop_webservice-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on patitas-and-co/prestashop-webservice
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prestashop_webservice-0.1.0-py3-none-any.whl -
Subject digest:
0e529adb5b9c29190c98122d701c2e4f00c5bfd95df2dd07025301c0fe4c992f - Sigstore transparency entry: 699690926
- Sigstore integration time:
-
Permalink:
patitas-and-co/prestashop-webservice@e86926b0b15e559d4276b172d593168758b808f6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/patitas-and-co
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e86926b0b15e559d4276b172d593168758b808f6 -
Trigger Event:
workflow_dispatch
-
Statement type: