Python async client library for the slskr HTTP API. This package is part of
the independent slskr project and is not affiliated with or endorsed by
Soulseek or its operators.
- ✅ Full async/await support
- ✅ Complete HTTP API coverage
- ✅ Batch operations
- ✅ WebSocket real-time events
- ✅ Automatic retries
- ✅ Comprehensive error handling
- ✅ Type hints
pip install slskr-api-clientimport asyncio
from slskr import SlskrClient
async def main():
async with SlskrClient(
base_url="http://127.0.0.1:5030",
token="your-bearer-token"
) as client:
# Get stats
stats = await client.get_stats()
print(stats)
# Create search
search = await client.create_search(query="artist name")
print(f"Search ID: {search['id']}")
# Get search results
results = await client.get_search_details(search['id'])
print(f"Found {len(results['results'])} results")
asyncio.run(main())from slskr import BatchClient
async def batch_example(client):
batch = BatchClient(client)
response = await batch.builder() \
.get("/api/stats", "stats") \
.get("/api/transfers", "transfers") \
.get("/api/messages", "messages") \
.execute()
print(f"Completed in {response.total_time_ms}ms")
print(f"Successful: {len(response.get_successful())}")
print(f"Failed: {len(response.get_failed())}")from slskr import WebSocketClient
async def websocket_example():
ws = WebSocketClient(
base_url="http://127.0.0.1:5030",
token="your-token"
)
# Listen to transfer events
@ws.on("transfer.completed")
async def on_transfer_completed(event):
print(f"Transfer completed: {event['data']}")
# Connect
await ws.connect()
# Subscribe to events
ws.subscribe("transfer.started", "transfer.completed", "transfer.failed")
# Keep connection open
try:
while True:
await asyncio.sleep(1)
finally:
await ws.disconnect()from slskr import SlskrClient, ApiError, TimeoutError
async def error_handling():
async with SlskrClient(...) as client:
try:
await client.get_transfer("invalid-id")
except ApiError as e:
if e.is_not_found():
print("Transfer not found")
elif e.is_unauthorized():
print("Invalid token")
elif e.is_conflict():
print("Transfer conflict")
else:
print(f"API error: {e.code}")
except TimeoutError:
print("Request timed out")Main HTTP client for REST API operations.
Health & Info
health()- Server healthversion()- Version infoget_capabilities()- API capabilitiesget_config()- Configurationget_stats()- Statistics
Search
list_searches(limit, offset)- List searchescreate_search(query, room, target)- Create searchget_search_details(search_id)- Search details
Messages
list_messages(limit, offset)- List messagesget_user_messages(username)- User messagessend_message(recipient, content)- Send messageacknowledge_message(message_id)- Mark read
Transfers
list_transfers(direction, status)- List transferscreate_transfer(direction, peer, filename)- Start transferget_transfer(transfer_id)- Transfer detailscancel_transfer(transfer_id)- Cancel transfer
Execute batch operations efficiently.
batch = BatchClient(client)
response = await batch.builder() \
.get("/api/stats") \
.post("/api/searches", {"query": "music"}) \
.delete("/api/transfers/123") \
.execute()Real-time event streaming.
ws = WebSocketClient(base_url, token)
await ws.connect()
ws.subscribe("transfer.started", "transfer.completed")
@ws.on("transfer.completed")
async def on_complete(event):
print(event)client = SlskrClient(
base_url="http://127.0.0.1:5030",
token="your-token",
timeout=30, # Request timeout in seconds
retries=3, # Retry attempts
retry_delay=1, # Delay between retries
debug=False # Enable debug logging
)Contributions welcome! Please see CONTRIBUTING.md
AGPL-3.0-only. See the repository LICENSE and NOTICE files for details.