prestashop-webservice 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ from dataclasses import dataclass
2
+ from enum import Enum
3
+
4
+
5
+ class SortOrder(Enum):
6
+ ASC = "ASC"
7
+ DESC = "DESC"
8
+
9
+
10
+ @dataclass
11
+ class Sort:
12
+ field: str
13
+ order: SortOrder
14
+
15
+
16
+ @dataclass
17
+ class Params:
18
+ """
19
+ Usage:
20
+ params = Params(
21
+ filter={"id_customer": "123"},
22
+ sort=Sort(field="date_add", order=SortOrder.DESC),
23
+ display=["id", "total_paid"],
24
+ limit=10
25
+ )
26
+ """
27
+
28
+ filter: dict | None = None
29
+ sort: Sort | None = None
30
+ display: list[str] | None = None
31
+ limit: int | None = None
32
+ date: bool | None = None
33
+
34
+ def to_dict(self) -> dict:
35
+ """Convert Params to a dictionary suitable for query parameters."""
36
+ params_dict = {}
37
+
38
+ # Add filters
39
+ if self.filter:
40
+ for key, value in self.filter.items():
41
+ # If value already has brackets (date ranges), don't add more
42
+ if isinstance(value, str) and value.startswith("[") and value.endswith("]"):
43
+ params_dict[f"filter[{key}]"] = value
44
+ else:
45
+ params_dict[f"filter[{key}]"] = f"[{value}]"
46
+
47
+ # Add sorting
48
+ if self.sort:
49
+ params_dict["sort"] = f"[{self.sort.field}_{self.sort.order.value}]"
50
+
51
+ # Add display fields
52
+ if self.display:
53
+ if "full" in self.display:
54
+ params_dict["display"] = "full"
55
+ else:
56
+ params_dict["display"] = f"[{','.join(self.display)}]"
57
+
58
+ # Add limit
59
+ if self.limit is not None:
60
+ params_dict["limit"] = str(self.limit)
61
+
62
+ ## Add date flag
63
+ if self.date is not None:
64
+ params_dict["date"] = "1" if self.date else "0"
65
+
66
+ return params_dict
67
+
68
+ def __hash__(self) -> int:
69
+ """Custom hash implementation to make Params hashable for caching purposes."""
70
+ return hash(
71
+ (
72
+ frozenset(self.filter.items()) if self.filter else None,
73
+ (self.sort.field, self.sort.order) if self.sort else None,
74
+ tuple(self.display) if self.display else None,
75
+ self.limit,
76
+ )
77
+ )
@@ -0,0 +1,54 @@
1
+ from typing import cast
2
+
3
+ from prestashop_webservice.base_model import BaseModel
4
+ from prestashop_webservice.models import ProductData
5
+ from prestashop_webservice.params import Params
6
+
7
+
8
+ class Product(BaseModel):
9
+ """Complex queries for products endpoint."""
10
+
11
+ _data_class = ProductData
12
+
13
+ def get_by_id(self, product_id: str) -> ProductData:
14
+ """Get product by ID."""
15
+ return cast(ProductData, self._query(f"products/{product_id}", None, "product"))
16
+
17
+ def get_by_category(self, category_id: str, limit: int = 50) -> list[ProductData]:
18
+ """Get products by category."""
19
+ params = Params(
20
+ filter={"id_category_default": category_id},
21
+ display=["id", "name", "reference", "price", "id_category_default"],
22
+ limit=limit,
23
+ )
24
+ return cast(list[ProductData], self._query("products", params, "products"))
25
+
26
+ def get_by_reference(self, reference: str) -> ProductData | None:
27
+ """Get product by reference."""
28
+ params = Params(
29
+ filter={"reference": reference},
30
+ display=["id", "reference", "name", "price"],
31
+ )
32
+ products = cast(list[ProductData], self._query("products", params, "products"))
33
+ return products[0] if products else None
34
+
35
+ def get_active(self, limit: int = 100) -> list[ProductData]:
36
+ """Get active products."""
37
+ params = Params(
38
+ filter={"active": "1"},
39
+ display=["id", "name", "reference", "active"],
40
+ limit=limit,
41
+ )
42
+ return cast(list[ProductData], self._query("products", params, "products"))
43
+
44
+ def get_image_url(self, product_id: str) -> str:
45
+ """Get the default image URL for a product."""
46
+ product = self.get_by_id(product_id)
47
+ img_id = str(product.id_default_image or "").strip()
48
+ slug = str(product.link_rewrite or "").strip()
49
+
50
+ if not (img_id and slug):
51
+ return ""
52
+
53
+ base_url = self.client.base_url
54
+ return f"{base_url}/{img_id}-large_default/{slug}.jpg"
@@ -0,0 +1,2 @@
1
+ # Marker file for PEP 561
2
+ # This file indicates that the package supports type checking
@@ -0,0 +1,12 @@
1
+ from prestashop_webservice.base_model import BaseModel
2
+ from prestashop_webservice.models import StateData
3
+
4
+
5
+ class State(BaseModel):
6
+ """Complex queries for states endpoint."""
7
+
8
+ _data_class = StateData
9
+
10
+ def get_by_id(self, state_id: str) -> StateData:
11
+ """Get state by ID (geographic state/province)."""
12
+ return self._query(f"states/{state_id}", None, "state")
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.4
2
+ Name: prestashop-webservice
3
+ Version: 0.3.0
4
+ Summary: Webservice client for PrestaShop API
5
+ Author-email: Nestor Villa <nestorvilla@patitasco.com>, Manolo Corte <manolocorte@patitasco.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Patitas and Co
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Documentation, https://github.com/patitas-and-co/prestashop-webservice/blob/main/README.md
29
+ Project-URL: Repository, https://github.com/patitas-and-co/prestashop-webservice
30
+ Keywords: prestashop,api,client,webservice,rest
31
+ Requires-Python: >=3.12
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+ Requires-Dist: httpx
35
+ Requires-Dist: cachetools
36
+ Requires-Dist: loguru
37
+ Requires-Dist: pre-commit
38
+ Provides-Extra: dev
39
+ Requires-Dist: pytest; extra == "dev"
40
+ Requires-Dist: pytest-cov; extra == "dev"
41
+ Requires-Dist: python-dotenv; extra == "dev"
42
+ Requires-Dist: ruff; extra == "dev"
43
+ Dynamic: license-file
44
+
45
+ # PrestaShop Webservice
46
+
47
+ Python client for PrestaShop API with caching, logging, and type hints.
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install prestashop-webservice
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ```python
58
+ from prestashop_webservice import Client, Params, Sort, SortOrder
59
+
60
+ # Initialize client
61
+ client = Client(
62
+ prestashop_base_url="https://your-store.com/api",
63
+ prestashop_ws_key="YOUR_API_KEY"
64
+ )
65
+
66
+ # Simple queries
67
+ order = client.query_order(order_id="123")
68
+ customer = client.query_customer(customer_id="456")
69
+
70
+ # Advanced queries with parameters
71
+ params = Params(
72
+ filter={"id_customer": "123"},
73
+ sort=Sort(field="date_add", order=SortOrder.DESC),
74
+ display=["id", "total_paid", "reference"],
75
+ limit=10
76
+ )
77
+ orders = client.query_orders(params=params)
78
+ ```
79
+
80
+ ## Features
81
+
82
+ - 🚀 HTTP client with connection pooling
83
+ - 💾 Automatic caching (24h TTL)
84
+ - 📝 Logging with Loguru
85
+ - 🎯 Full type hints
86
+ - 🔒 Singleton pattern
87
+
88
+ ## Available Methods
89
+
90
+ - `query_order()`, `query_orders()`, `exists_order()`
91
+ - `query_customer()`, `query_customers()`
92
+ - `query_product()`, `query_address()`, `query_country()`
93
+ - `query_order_carriers()`, `query_order_histories()`, `query_order_state()`
94
+
95
+ ## License
96
+
97
+ MIT License - See [LICENSE](LICENSE) file for details.
@@ -0,0 +1,28 @@
1
+ prestashop_webservice/__init__.py,sha256=bO9RuLEm-NZH5rvTocgJLzbhReshGdYpnF_m3ajD4tU,2175
2
+ prestashop_webservice/address.py,sha256=Q7RUL2oN7Y0OCmo68N5n-iSrKbWSJfIrfhiDc44HkhY,1086
3
+ prestashop_webservice/base_model.py,sha256=jLlmoCBPq2i0Yzve5O0fKGjgCAzXoUvhY2pUMS5nAcw,4332
4
+ prestashop_webservice/carrier.py,sha256=Essfzkc347EHLz1JizhkvC8Pld2WDXz8opwgk37iuQ0,1302
5
+ prestashop_webservice/client.py,sha256=JhmDA57jVsMJWlsWf-UnAXQCCrAkm3p3wLbMhc1AqoE,7041
6
+ prestashop_webservice/combination.py,sha256=q-nvpeV4EmZJz1Sgbn9zuQc5PeBS9XPnmPw3ht42HUA,1078
7
+ prestashop_webservice/config.py,sha256=_eW1l-9H4JYf_5ASkYngJOJdCt0M57GtfjjqpuOIlCE,163
8
+ prestashop_webservice/country.py,sha256=u45oqOk2HMGWQK2TRSLeGU1IbY06H0cPqyK_msD___s,1056
9
+ prestashop_webservice/customer.py,sha256=19zdBOwRvY9x5tQVG39dAfjT-bova3KQxL3hLgkxjzY,1579
10
+ prestashop_webservice/customer_message.py,sha256=AHtPEU2ZcaltUE22AbJN5Ng75OjBonGah96FQ5BrCMY,1255
11
+ prestashop_webservice/customer_thread.py,sha256=0EFv7IpyGbj4udBQeqvkJNi-c4aUVI6GZVDXaXLpXy0,1034
12
+ prestashop_webservice/image_product.py,sha256=ISJ_3ZIPInSEmaVRc70sfngoiEpH0Lw4r2cWnZ0nqBw,427
13
+ prestashop_webservice/logger.py,sha256=LMFUQIX7r2BA1LtL2Ryq2I3SR07-UzfuP7TEDeLoVl4,627
14
+ prestashop_webservice/models.py,sha256=gJT37vkw0rcVy8pVNucn9k56hTziBs3pp7XoAwIMP-I,12742
15
+ prestashop_webservice/order.py,sha256=iLtqvoxksxqQhBEpMGk9SIl1Bb-wRW_6-e5K8AionMU,4379
16
+ prestashop_webservice/order_carrier.py,sha256=GNUtQjC21aL0VEetcU5QtvaVq5Ej1qgFbF-m-c_kKLQ,1305
17
+ prestashop_webservice/order_detail.py,sha256=VzJA1YUQGYliC0gb-p_yDcOwVOcvoaDWgCc-GS-wQe8,1125
18
+ prestashop_webservice/order_history.py,sha256=PrmpA31z9DYoVAWjGqcfVEOuNNnHvCYOI4bkMkH9iFI,2330
19
+ prestashop_webservice/order_state.py,sha256=9ponPxriu4YoNNLDEitMuRntItfAVOJxEjIkDwpd0QE,401
20
+ prestashop_webservice/params.py,sha256=KUcqnWVrrGxjghV0LAbrMC3cBhAIA2sjQzm5Ccn8i2c,2166
21
+ prestashop_webservice/product.py,sha256=2XjqpuxmxwmR00D-2hhbtjUdvTAP5oc1jyAAwnnYxD4,2036
22
+ prestashop_webservice/py.typed,sha256=WJtVGe64tcQSssSo4RD7zCf_3u7X2BmFCWDCroWOcaQ,88
23
+ prestashop_webservice/state.py,sha256=Iub8Ooe_dxY-LuUosTDbSxtADicQIT9RRwJz80pZJDc,385
24
+ prestashop_webservice-0.3.0.dist-info/licenses/LICENSE,sha256=mbRCKL3jFTGOJiU0MXMXeRWO439mLko7y5s_f5hQfb0,1071
25
+ prestashop_webservice-0.3.0.dist-info/METADATA,sha256=0TTzHvteRxZt8lxkmJeQojDpkbpfivHF4Ekxhm4NQ1w,3315
26
+ prestashop_webservice-0.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
+ prestashop_webservice-0.3.0.dist-info/top_level.txt,sha256=W57_kSLnXlqYufTCGD5fuq6CceW0D_Tcgr5B7LU5wHA,22
28
+ prestashop_webservice-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Patitas and Co
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ prestashop_webservice