A modern Python client library for the Allegro REST API with 100% API coverage.
- 100% API Coverage - All Allegro REST API endpoints implemented
- Full OAuth2 authentication support (device flow, authorization code, client credentials)
- Automatic token refresh
- Type hints for better IDE support
- Comprehensive error handling
- Support for both production and sandbox environments
- Easy-to-use interface for common operations
pip install allegro-apifrom allegro_api import AllegroAPI
# Initialize client
api = AllegroAPI(
client_id="your_client_id",
client_secret="your_client_secret", # Optional for device flow
sandbox=False # Use True for sandbox environment
)
# Authenticate using device flow
api.authenticate()
# Get current user info
user = api.user.get_me()
print(f"Hello, {user['login']}!")
# Search for offers
results = api.search_offers(
phrase="laptop",
category_id="491",
limit=10
)
for offer in results['offers']:
print(f"{offer['name']} - {offer['sellingMode']['price']['amount']} PLN")# Simple authentication - opens browser automatically
api.authenticate()
# Manual authentication - displays URL and code
api.authenticate(open_browser=False)# Get authorization URL
auth_url = api.get_authorization_url(state="random_state")
# Redirect user to auth_url
# After user authorization, exchange code for token
api.authenticate(method="code", code="received_authorization_code")api.authenticate(method="client_credentials")api = AllegroAPI(
access_token="existing_access_token",
refresh_token="existing_refresh_token"
)# Get your active offers
my_offers = api.offers.list(
publication_status=["ACTIVE"],
limit=50
)
for offer in my_offers['offers']:
print(f"{offer['name']} (ID: {offer['id']})")# Create offer from product
offer = api.offers.create_from_product(
product_id="product_id_from_allegro",
parameters={
"price": {"amount": "99.99", "currency": "PLN"},
"stock": {"available": 10},
"publication": {"status": "ACTIVE"}
}
)
# Create custom offer
offer_data = {
"name": "My Product",
"category": {"id": "491"},
"parameters": [...],
"images": [...],
"sellingMode": {
"format": "BUY_NOW",
"price": {"amount": "99.99", "currency": "PLN"}
},
"stock": {"available": 10},
"publication": {"status": "ACTIVE"}
}
offer = api.offers.create(offer_data)# Update entire offer
updated_offer = api.offers.update(offer_id, updated_data)
# Update specific fields
api.offers.patch(offer_id, [
{"op": "replace", "path": "/name", "value": "New Name"},
{"op": "replace", "path": "/stock/available", "value": 5}
])
# Quick price update
api.offers.update_price(offer_id, amount=79.99)
# Quick stock update
api.offers.update_quantity(offer_id, quantity=20)# Publish draft offer
api.offers.publish(offer_id)
# Unpublish offer
api.offers.unpublish(offer_id)
# End offer
api.offers.delete(offer_id)# List recent orders
orders = api.orders.list(
status="READY_FOR_PROCESSING",
limit=20
)
# Get order details
order = api.orders.get(order_id)
# Create shipment
api.orders.create_shipment(
order_id=order_id,
carrier_id="ALLEGRO_COURIER",
carrier_name="Allegro Courier",
tracking_number="123456789"
)# Browse categories
root_categories = api.categories.list()
subcategories = api.categories.list(parent_id="491")
# Get category details with parameters
category = api.categories.get("491")
parameters = api.categories.get_parameters("491")
# Search categories
matching = api.categories.search("laptop")from allegro_api.exceptions import (
AllegroAPIException,
AuthenticationError,
RateLimitError,
ValidationError
)
try:
api.offers.create(offer_data)
except ValidationError as e:
print(f"Validation failed: {e}")
print(f"Details: {e.response_data}")
except RateLimitError as e:
print(f"Rate limit hit, retry after {e.retry_after} seconds")
except AuthenticationError:
# Token might be expired, try refreshing
api.refresh_access_token()
except AllegroAPIException as e:
print(f"API error: {e}")# Configure timeouts and retries
api = AllegroAPI(
client_id="your_client_id",
timeout=60, # Request timeout in seconds
max_retries=5, # Maximum retry attempts
backoff_factor=0.5 # Retry backoff factor
)# Manual pagination
all_offers = []
offset = 0
limit = 100
while True:
response = api.offers.list(limit=limit, offset=offset)
offers = response['offers']
if not offers:
break
all_offers.extend(offers)
offset += len(offers)
if len(offers) < limit:
break# Batch update multiple offers
operations = [
{
"offer": {"id": "offer1_id"},
"modification": {
"changeType": "PRICE",
"price": {"amount": "99.99", "currency": "PLN"}
}
},
{
"offer": {"id": "offer2_id"},
"modification": {
"changeType": "QUANTITY",
"quantity": {"available": 5}
}
}
]
result = api.offers.batch_update(operations)
command_id = result['id']
# Check batch status
status = api.offers.get_batch_status(command_id)You can use environment variables for configuration:
export ALLEGRO_CLIENT_ID=your_client_id
export ALLEGRO_CLIENT_SECRET=your_client_secret
export ALLEGRO_SANDBOX=falseimport os
from allegro_api import AllegroAPI
api = AllegroAPI(
client_id=os.getenv('ALLEGRO_CLIENT_ID'),
client_secret=os.getenv('ALLEGRO_CLIENT_SECRET'),
sandbox=os.getenv('ALLEGRO_SANDBOX', 'false').lower() == 'true'
)Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Official Allegro API Documentation
- Library Documentation
- PyPI Package
- GitHub Repository
- Changelog
- Contributing Guidelines
For API-related issues, please check the official Allegro API documentation.
For library-specific issues, please open an issue on GitHub.
Created and maintained by Marek Sybilak (marek.sybilak@neogento.com)