Phase 2, Task 2.1, Steps 1-3 Complete: Async Client Architecture
This commit introduces comprehensive async/await support for the Wiki.js
Python SDK, providing high-performance concurrent operations using aiohttp.
Key Features:
------------
1. **AsyncWikiJSClient** (wikijs/aio/client.py)
- Full async/await support with aiohttp
- Connection pooling (100 connections, 30 per host)
- Async context manager support (async with)
- Same interface as sync client for easy migration
- Proper resource cleanup and session management
- DNS caching for improved performance
2. **Async Endpoints** (wikijs/aio/endpoints/)
- AsyncBaseEndpoint - Base class for all async endpoints
- AsyncPagesEndpoint - Complete async Pages API
* list() - List pages with filtering
* get() - Get page by ID
* get_by_path() - Get page by path
* create() - Create new page
* update() - Update existing page
* delete() - Delete page
* search() - Search pages
* get_by_tags() - Filter by tags
3. **Architecture**
- Mirrors sync client structure for consistency
- Reuses existing models, exceptions, and utilities
- Optional dependency (aiohttp) via extras_require
- Zero breaking changes to sync API
Performance Benefits:
--------------------
- Designed for >3x throughput vs sync client
- Efficient connection pooling and reuse
- Concurrent request handling
- Reduced latency with TCP keepalive
Usage Example:
--------------
```python
from wikijs.aio import AsyncWikiJSClient
async with AsyncWikiJSClient(url, auth='key') as client:
# Concurrent operations
pages = await client.pages.list()
page = await client.pages.get(123)
# Create/Update/Delete
new_page = await client.pages.create(page_data)
updated = await client.pages.update(123, updates)
await client.pages.delete(123)
```
Installation:
-------------
```bash
pip install wikijs-python-sdk[async]
```
Quality Metrics:
----------------
- ✅ All imports successful
- ✅ Black formatting applied
- ✅ Flake8 passing (complexity warnings expected)
- ✅ MyPy type checking (minor issues in base models)
- ✅ Zero breaking changes to sync API
Next Steps:
-----------
- Comprehensive async unit tests
- Integration tests with real Wiki.js instance
- Performance benchmarks (async vs sync)
- Documentation and usage examples
This lays the foundation for high-performance async operations
in the Wiki.js Python SDK.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
95 lines
2.3 KiB
Python
95 lines
2.3 KiB
Python
"""Wiki.js Python SDK - Professional SDK for Wiki.js API integration.
|
|
|
|
This package provides a comprehensive Python SDK for interacting with Wiki.js
|
|
instances, including support for pages, users, groups, and system management.
|
|
|
|
Example:
|
|
Synchronous usage:
|
|
|
|
>>> from wikijs import WikiJSClient
|
|
>>> client = WikiJSClient('https://wiki.example.com', auth='your-api-key')
|
|
>>> pages = client.pages.list()
|
|
|
|
Asynchronous usage (requires aiohttp):
|
|
|
|
>>> from wikijs.aio import AsyncWikiJSClient
|
|
>>> async with AsyncWikiJSClient('https://wiki.example.com', auth='key') as client:
|
|
... pages = await client.pages.list()
|
|
|
|
Features:
|
|
- Synchronous and asynchronous clients
|
|
- Type-safe data models with validation
|
|
- Comprehensive error handling
|
|
- Automatic retry logic with exponential backoff
|
|
- Professional logging and debugging support
|
|
- Context manager support for resource cleanup
|
|
- High-performance async operations with connection pooling
|
|
"""
|
|
|
|
from .auth import APIKeyAuth, AuthHandler, JWTAuth, NoAuth
|
|
from .client import WikiJSClient
|
|
from .exceptions import (
|
|
APIError,
|
|
AuthenticationError,
|
|
ClientError,
|
|
ConfigurationError,
|
|
ConnectionError,
|
|
NotFoundError,
|
|
PermissionError,
|
|
RateLimitError,
|
|
ServerError,
|
|
TimeoutError,
|
|
ValidationError,
|
|
WikiJSException,
|
|
)
|
|
from .models import BaseModel, Page, PageCreate, PageUpdate
|
|
from .version import __version__, __version_info__
|
|
|
|
# Public API
|
|
__all__ = [
|
|
# Main client
|
|
"WikiJSClient",
|
|
# Authentication
|
|
"AuthHandler",
|
|
"NoAuth",
|
|
"APIKeyAuth",
|
|
"JWTAuth",
|
|
# Data models
|
|
"BaseModel",
|
|
"Page",
|
|
"PageCreate",
|
|
"PageUpdate",
|
|
# Exceptions
|
|
"WikiJSException",
|
|
"APIError",
|
|
"AuthenticationError",
|
|
"ConfigurationError",
|
|
"ValidationError",
|
|
"ClientError",
|
|
"ServerError",
|
|
"NotFoundError",
|
|
"PermissionError",
|
|
"RateLimitError",
|
|
"ConnectionError",
|
|
"TimeoutError",
|
|
# Version info
|
|
"__version__",
|
|
"__version_info__",
|
|
]
|
|
|
|
# Package metadata
|
|
__author__ = "Wiki.js SDK Contributors"
|
|
__email__ = ""
|
|
__license__ = "MIT"
|
|
__description__ = "Professional Python SDK for Wiki.js API integration"
|
|
__url__ = "https://github.com/yourusername/wikijs-python-sdk"
|
|
|
|
# For type checking
|
|
__all__ += [
|
|
"__author__",
|
|
"__email__",
|
|
"__license__",
|
|
"__description__",
|
|
"__url__",
|
|
]
|