Skip to main content

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="") โ†’ dict
  • query_orders(params=None) โ†’ list
  • exists_order(order_id) โ†’ bool
Customers
  • query_customer(params=None, customer_id="") โ†’ dict
  • query_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:

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prestashop_webservice-0.1.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

prestashop_webservice-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for prestashop_webservice-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d016a5c4397aae1a3f2fc4984eb14e55f3e5af590ce4880a13b1ab9378d044dd
MD5 8ed70b5a7c2f6c9dbf005266784dc904
BLAKE2b-256 749388ac99511cf04a0f3744eba9ea04c06f66c2024b84ce9063963004b9cddf

See more details on using hashes here.

Provenance

The following attestation bundles were made for prestashop_webservice-0.1.0.tar.gz:

Publisher: publish.yml on patitas-and-co/prestashop-webservice

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prestashop_webservice-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prestashop_webservice-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e529adb5b9c29190c98122d701c2e4f00c5bfd95df2dd07025301c0fe4c992f
MD5 80ec3373e5ce88fbb283b30546fa137b
BLAKE2b-256 02308cd769fd818415ec77029ba18c1298bb5e7891593ff5b7e2cb8d0abcb697

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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