Swotzy API python wrapper
Project description
Swotzy API Client
Modern Python client for Swotzy API with support for both synchronous and asynchronous operations.
Features
- Support for synchronous and asynchronous operations
- Strong typing using Pydantic
- Simple and intuitive interface
- Flexible configuration
- Built-in support for main Swotzy API endpoints
- Support for various courier services
Installation
pip install swotzypy
Basic Example
from swotzypy import Client, Address, OrderCreate, DeliveryConfigClassic
from swotzypy.api.enums import CarrierEnum
# Create client with Basic Auth
client = Client(
public_key="your-public-key",
private_key="your-private-key"
)
# Create order
order = OrderCreate(
carrier=CarrierEnum.DPD,
service="CLASSIC",
delivery_config=DeliveryConfigClassic(),
address_sender=Address(
full_name="John Doe",
phone="+37122345678",
email="john@example.com",
address1="Example street 1",
zip="LV-1001",
city="Riga",
country="LV"
),
address_recipient=Address(
full_name="Jane Smith",
phone="+37122345679",
email="jane@example.com",
address1="Another street 2",
zip="LV-1002",
city="Riga",
country="LV"
),
shipments=[{
"package": {
"length": 20,
"width": 15,
"height": 10,
"weight": 1.5
}
}]
)
# Synchronous operations
created_order = client.orders.create(order)
order_details = client.orders.get(created_order.id)
tracking_info = client.tracking.get_events(order_details.shipments[0].tracking_number)
# Asynchronous operations
async def main():
created_order = await client.orders.acreate(order)
order_details = await client.orders.aget(created_order.id)
tracking_info = await client.tracking.aget_events(order_details.shipments[0].tracking_number)
Working with Parcel Points
# Get list of parcel points
parcelshops = client.parcelshops.list(country="LV", carrier="DPD")
# Create order with delivery to parcel point
from swotzypy import DeliveryConfigParcelshop
order = OrderCreate(
carrier=CarrierEnum.DPD,
service="PARCELSHOP",
delivery_config=DeliveryConfigParcelshop(
parcelshop_id=parcelshops[0].id
),
# ... other fields as in the previous example
)
Configuration Using Builder
from swotzypy import Client, ClientConfig
config = (ClientConfig.builder()
.base_url("https://api.swotzy.com")
.timeout(30.0)
.retries(3)
.proxies({"http": "http://proxy:8080"})
.build())
client = Client.from_config(config,
public_key="<your-public-key>",
private_key="<your-private-key>")
Architecture
The project follows architecture principles and uses the following design patterns:
- Facade: The main
Clientclass provides a simple interface for all API capabilities - Strategy: The authentication module supports various authentication strategies (Basic Auth)
- Builder: Client configuration is implemented through the Builder pattern
Modules
Core
- client.py: Implements the Facade pattern, combining all API functionalities
- http.py: Low-level layer for handling HTTP requests
- config.py: Client configuration using the Builder pattern
Auth
- auth.py: Implements Basic Auth for Swotzy API
API
- models.py: Pydantic models for data typing
- enums.py: Enumerations for statuses, delivery types, and courier services
- endpoints.py: High-level methods for working with API:
- Orders: creation and management of orders
- Parcelshops: working with parcel points
- Rates: delivery cost calculation
- Tracking: shipment tracking
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
swotzypy-0.1.0.tar.gz
(11.4 kB
view details)
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
swotzypy-0.1.0-py3-none-any.whl
(10.8 kB
view details)
File details
Details for the file swotzypy-0.1.0.tar.gz.
File metadata
- Download URL: swotzypy-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b0f7f42aa8d185f9645d12c54c6b2728f6c6e5c760fc129b29dcc5bfacbfa49
|
|
| MD5 |
0a6fc1f078dc10f8cfe5526568bced4d
|
|
| BLAKE2b-256 |
22f8b061db08df2d06216b942a696fceeb58186949ab4615a158a0ba4787f85d
|
File details
Details for the file swotzypy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: swotzypy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63e9367612c4167b1c15a768c4fdc232da74abe572321e0b8e1b406824ba97fa
|
|
| MD5 |
312d1eea1b53c9d794286b78ffcdb827
|
|
| BLAKE2b-256 |
f7085517a99fbe3019cb79063ed67e659585adcd8aefe1526dde752acef1dff5
|