ShopCloud Proxy Client
Ein einfacher Python-Client für die ShopCloud Proxy API. Funktioniert als Drop-in-Replacement für requests - ohne komplexe Änderungen an Ihrem bestehenden Code!
Features
- ✨ Einfach zu verwenden: Minimale Änderungen an bestehendem Code nötig
- 🔄 Kompatibel mit requests: Gleiche API wie
requests.Session - 🔐 Automatische Authentifizierung: Token-Verwaltung erfolgt automatisch
- 🔁 Automatisches Retry: Bei transienten Fehlern (502, 503, 504) wird automatisch wiederholt
- ⚡ Proaktiver Token-Refresh: Token wird erneuert bevor er abläuft
- 🎯 Bessere Error Messages: Spezifische Exceptions für verschiedene Fehlertypen
- 🚀 Keine komplexen Änderungen: Einfach Session erstellen und loslegen
Installation
# Aus lokalem Verzeichnis installieren
cd client
pip install -e .
# Oder mit pip (wenn auf PyPI veröffentlicht)
pip install shopcloud-proxy-client
Schnellstart
Variante 1: ProxySession (empfohlen)
from shopcloud_proxy_client import ProxySession
# Session erstellen (automatisches Login)
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
)
# Einfach verwenden wie requests!
response = session.get("https://api.github.com/users/octocat")
print(response.json())
print(f"Status: {response.status_code}")
# POST mit JSON
response = session.post(
"https://httpbin.org/post",
json={"name": "Test", "value": 123}
)
print(response.json())
# Mit Custom Headers
response = session.get(
"https://api.example.com/data",
headers={"X-API-Key": "secret123"}
)
Variante 2: Globale Konfiguration
import shopcloud_proxy_client as proxy
# Einmalig konfigurieren
proxy.configure(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
)
# Dann einfach verwenden
response = proxy.get("https://api.github.com/users/octocat")
print(response.json())
response = proxy.post("https://httpbin.org/post", json={"key": "value"})
Variante 3: Context Manager
from shopcloud_proxy_client import ProxySession
with ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
) as session:
response = session.get("https://api.github.com/zen")
print(response.text)
# Session wird automatisch geschlossen
Bestehenden Code migrieren
Vorher (mit requests):
import requests
response = requests.get("https://api.github.com/users/octocat")
print(response.json())
response = requests.post(
"https://api.example.com/data",
json={"name": "test"},
headers={"X-API-Key": "secret"}
)
Nachher (mit Proxy):
from shopcloud_proxy_client import ProxySession
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
)
# Rest des Codes bleibt GLEICH!
response = session.get("https://api.github.com/users/octocat")
print(response.json())
response = session.post(
"https://api.example.com/data",
json={"name": "test"},
headers={"X-API-Key": "secret"}
)
API-Dokumentation
ProxySession
ProxySession(
proxy_url: str, # URL der Proxy API
username: str, # Ihr Username
password: str, # Ihr Passwort
auto_login: bool = True, # Automatisch beim Start einloggen
default_timeout: int = 30, # Standard-Timeout in Sekunden
default_headers: Dict[str, str] = None,# Standard-Headers für alle Requests
max_retries: int = 3, # Anzahl der Wiederholungen bei Fehlern
retry_delay: float = 1.0 # Verzögerung zwischen Retries in Sekunden
)
Methoden:
get(url, **kwargs)- GET Requestpost(url, **kwargs)- POST Requestput(url, **kwargs)- PUT Requestpatch(url, **kwargs)- PATCH Requestdelete(url, **kwargs)- DELETE Requestoptions(url, **kwargs)- OPTIONS Requesthead(url, **kwargs)- HEAD Request
Unterstützte kwargs:
headers: Dict mit Custom Headersjson: JSON Body (wird automatisch serialisiert)data: Raw Body Datatimeout: Timeout in Sekunden (überschreibt Standard)
ProxyResponse
Das Response-Objekt ist kompatibel mit requests.Response:
response = session.get("https://api.example.com")
# Attribute
response.status_code # HTTP Status Code (int)
response.headers # Response Headers (dict)
response.ok # True wenn 200-299 (bool)
response.url # Original URL (str)
response.text # Body als String (str)
response.content # Body als Bytes (bytes)
# Methoden
response.json() # Parse JSON
response.raise_for_status() # Raise Exception bei Fehler
Erweiterte Beispiele
Mit Error Handling
from shopcloud_proxy_client import ProxySession
import requests
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
)
try:
response = session.get("https://api.example.dev/data")
response.raise_for_status() # Raise bei 4xx/5xx
data = response.json()
print(f"Success: {data}")
except requests.HTTPError as e:
print(f"HTTP Error: {e}")
except Exception as e:
print(f"Error: {e}")
Mehrere Requests mit einer Session
from shopcloud_proxy_client import ProxySession
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
)
# Token wird automatisch wiederverwendet
users = ["octocat", "torvalds", "gvanrossum"]
for user in users:
response = session.get(f"https://api.github.com/users/{user}")
data = response.json()
print(f"{user}: {data.get('name')}")
Custom Timeout
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort",
default_timeout=60 # 60 Sekunden Standard
)
# Oder per Request
response = session.get("https://slow-api.example.com", timeout=120)
Default Headers
# Session mit Standard-Headers erstellen
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort",
default_headers={
"User-Agent": "MyApp/1.0",
"Accept": "application/json",
"X-Client-ID": "my-client"
}
)
# Diese Headers werden automatisch bei jedem Request mitgesendet
response = session.get("https://api.example.com/data")
# Request-spezifische Headers überschreiben Default-Headers
response = session.get(
"https://api.example.com/data",
headers={
"User-Agent": "SpecialAgent/2.0", # Überschreibt Default
"X-Request-ID": "123" # Zusätzlicher Header
}
)
# Resultierende Headers: User-Agent=SpecialAgent/2.0, Accept=application/json,
# X-Client-ID=my-client, X-Request-ID=123
Automatisches Retry & Error Handling
from shopcloud_proxy_client import (
ProxySession,
ProxyRateLimitError,
ProxyTimeoutError,
ProxyAuthenticationError
)
# Session mit Custom Retry-Einstellungen
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort",
max_retries=5, # 5 Versuche statt 3
retry_delay=0.5 # 0.5 Sekunden zwischen Versuchen
)
# Automatisches Retry bei 502, 503, 504 Fehlern
# Mit exponentiellem Backoff: 0.5s, 1.0s, 1.5s, 2.0s, 2.5s
try:
response = session.get("https://unreliable-api.example.com")
except ProxyRateLimitError:
print("Rate Limit erreicht")
except ProxyTimeoutError:
print("Request hat zu lange gedauert")
except ProxyAuthenticationError:
print("Authentifizierung fehlgeschlagen")
Proaktiver Token-Refresh
# Token wird automatisch 30 Sekunden vor Ablauf erneuert
# Keine manuellen Eingriffe nötig!
session = ProxySession(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
)
# Token-Ablauf wird aus JWT extrahiert und überwacht
# Bei jedem Request wird geprüft, ob Token bald abläuft
# Falls ja: automatischer Refresh VOR dem Request
for i in range(1000):
response = session.get("https://api.example.com/data")
# Token wird automatisch erneuert wenn nötig
Unterschiede zu requests
Der Client ist weitgehend kompatibel mit requests, aber es gibt einige Einschränkungen:
Unterstützt:
- ✅ HTTP Methoden (GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD)
- ✅ Custom Headers
- ✅ JSON und String Bodies
- ✅ Timeout
- ✅ Response Parsing (json(), text, content)
- ✅ Error Handling (raise_for_status)
Nicht unterstützt:
- ❌ Datei-Uploads (files parameter)
- ❌ Streaming Responses
- ❌ Session Cookies
- ❌ SSL Verification Parameter
- ❌ Proxies Parameter (wird ja schon geproxyt!)
Entwicklung
Tests ausführen
cd client
pip install -e ".[dev]"
pytest tests/
Code-Qualität prüfen
ruff check .
Troubleshooting
"Proxy client not configured"
Wenn Sie die globalen Funktionen (proxy.get()) verwenden, müssen Sie zuerst configure() aufrufen:
import shopcloud_proxy_client as proxy
proxy.configure(
proxy_url="https://test-proxy.example.dev",
username="ihr-username",
password="ihr-passwort"
)
response = proxy.get("https://api.example.com")
Oder verwenden Sie direkt ProxySession.
Token abgelaufen
Der Client erneuert automatisch abgelaufene Tokens. Wenn Sie einen 401-Fehler sehen, überprüfen Sie Ihre Credentials.
Timeouts
Standardmäßig ist der Timeout 30 Sekunden. Für langsame APIs erhöhen Sie ihn:
response = session.get("https://slow-api.example.com", timeout=120)
Lizenz
MIT
Support
Bei Fragen oder Problemen öffnen Sie bitte ein Issue auf GitHub.
Metadata
Release files for shopcloud-proxy-client 0.30.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shopcloud_proxy_client-0.30.0.tar.gz | 13.5 kB | With provenance | Details for shopcloud_proxy_client-0.30.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shopcloud_proxy_client-0.30.0-py3-none-any.whl | Python 3 | none | any | Details for shopcloud_proxy_client-0.30.0-py3-none-any.whl |
Total release size: 24.0 kB
Release files / shopcloud_proxy_client-0.30.0.tar.gz
| Download URL | shopcloud_proxy_client-0.30.0.tar.gz |
|---|---|
| Size | 13.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c90054c822f85fcc1af4fe571a9ad5f2f687fa195138739cb83952de6f6e2bd9
|
|
BLAKE2b-256 checksum How to use checksums |
a1c7e09983e2dd12aab5fc470afa322d72ebe9eb2846a5ce9eec5c1db6b40834
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logRelease files / shopcloud_proxy_client-0.30.0-py3-none-any.whl
| Download URL | shopcloud_proxy_client-0.30.0-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e5b2423338a70b7bd196dd530250525c40e2edce5487ef6faa5543bb8579dcf8
|
|
BLAKE2b-256 checksum How to use checksums |
44ea0ceb0fb8874b24088558c46d0349bd059cfc5f6817d6706d4deb533b9521
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logSecurity for shopcloud-proxy-client 0.30.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for shopcloud_proxy_client-0.30.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.