SMW Readerο
A modular Python client library for accessing Semantic MediaWiki (SMW) API endpoints.
Featuresο
π Fluent Query Builder: A programmatic and readable way to construct complex queries.
π― Convenience Methods: A purpose-built method for querying categories (
query_category).ποΈ Modular Design: Following the open/closed principle, easily extensible with new API endpoints.
π‘οΈ Type Safety: Full type hints throughout the codebase.
π¨ Robust Error Handling: Custom exceptions for different error scenarios.
π¦ No External Dependencies: Uses only Python standard library for HTTP requests.
π§ͺ Comprehensive Testing: Full test suite with pytest.
Installationο
# Recommended: Install with uv (fast, modern Python package manager)
uv add smw-reader
# Or with optional HTTP client support
uv add 'smw-reader[aiohttp]' # For async HTTP with aiohttp
uv add 'smw-reader[httpx]' # For async HTTP with httpx
uv add 'smw-reader[async]' # For full async support
# Alternatively, use pip directly
pip install smw-reader
# Development installation
git clone <repository-url>
cd smw-reader
uv sync
Quick Startο
from smw_reader import SMWClient, QueryBuilder
# Create a client instance
site = SMWClient("https://your-wiki.org/w/")
# Build a query using the QueryBuilder
builder = QueryBuilder()
builder.add_conditions("Category:Person").add_printouts("Name", "Age")
# Execute the query
result = site.ask.query(builder, limit=10)
print(result)
# You can also use the convenience method for categories
result_category = site.ask.query_category("Person", printouts=["Name", "Age"], limit=10)
print(result_category)
Building Queriesο
The recommended way to build queries is using the QueryBuilder, which provides a fluent interface for adding conditions and printouts.
from smw_reader import QueryBuilder
# Start with a new builder
builder = QueryBuilder()
# Chain methods to add conditions and printouts
builder.add_conditions(
"Category:Software",
"License::GPL"
).add_printouts(
"Name",
"Homepage URL",
"Version"
)
# The builder can be passed directly to the query method
result = site.ask.query(builder, limit=20)
For more advanced use cases, including raw query strings and dictionary-based conditions, please see the detailed examples in the documentation.
Convenience Methodsο
For common tasks, convenience methods provide a simpler interface.
query_category()ο
Query all pages in a specific category.
# Query by category - printouts are auto-formatted
result = site.ask.query_category(
category="Software",
printouts=["Name", "License", "Version"], # No "?" prefix needed!
limit=20
)
Error Handlingο
The library provides specific exceptions for different error scenarios:
from smw_reader.exceptions import (
SMWAPIError, # Base API error
SMWConnectionError, # Network/connection issues
SMWServerError, # Server-side errors
SMWValidationError, # Invalid parameters
SMWAuthenticationError # Authentication failures
)
try:
result = site.ask.query("[[Category:Test]]")
except SMWConnectionError:
print("Network issue")
except SMWAPIError as e:
print(f"API error: {e}")
Architectureο
The library follows a modular architecture:
SMWClient: Main client class that handles HTTP requests and endpoint registration.APIEndpoint: Abstract base class for API endpoints.QueryBuilder: A fluent interface for building query strings.HTTPClient: Abstract interface for HTTP clients.RequestsHTTPClient: Concrete implementation using urllib.
Developmentο
See the projectβs development guide in the documentation (docs/sphinx/DEVELOPMENT.md) for setup, workflow, and contributing information.
- API Reference
- SMW Reader Usage Examples
- Semantic MediaWiki (SMW) Query Syntax
- Changelog
- Unreleased (2025-12-20)
- v0.8.7 (2025-12-20)
- v0.8.6 (2025-12-20)
- v0.8.5 (2025-12-20)
- v0.8.3 (2025-12-20)
- v0.8.4 (2025-12-17)
- v0.8.2 (2025-11-02)
- v0.8.1 (2025-11-02)
- v0.8.0 (2025-11-02)
- v0.7.11 (2025-10-27)
- v0.0.1 (2025-10-27)
- v0.7.10 (2025-10-27)
- v0.7.9 (2025-10-27)
- v0.7.8 (2025-10-26)
- v0.7.7 (2025-10-26)
- v0.7.6 (2025-10-25)
- v0.7.5 (2025-10-25)
- v0.7.3 (2025-10-20)
- v0.7.2 (2025-10-20)
- v0.7.1 (2025-10-20)
- v0.7.0 (2025-10-20)
- v0.6.26 (2025-10-20)
- v0.6.25 (2025-10-20)
- v0.6.24 (2025-10-20)
- v0.6.23 (2025-10-20)
- v0.6.21 (2025-10-20)
- v0.6.20 (2025-10-20)
- v0.6.22 (2025-10-20)
- v0.6.19 (2025-10-20)
- v0.6.17 (2025-10-20)
- v0.6.16 (2025-10-20)
- v0.6.14 (2025-10-20)
- v0.6.13 (2025-10-19)
- v0.6.12 (2025-10-19)
- v0.6.11 (2025-10-19)
- v0.6.10 (2025-10-19)
- v0.6.9 (2025-10-19)
- v0.6.8 (2025-10-19)
- v0.6.7 (2025-10-19)
- v0.6.6 (2025-10-19)
- v0.6.5 (2025-10-19)
- v0.6.4 (2025-10-19)
- v0.6.3 (2025-10-19)
- v0.6.2 (2025-10-19)
- v0.6.1 (2025-10-19)
- v0.5.1 (2025-10-18)
- v0.5.0 (2025-10-18)
- v0.4.2 (2025-10-18)
- v0.4.1 (2025-10-18)
- v0.4.0 (2025-10-18)
- v0.3.0 (2025-10-18)
- v0.2.6 (2025-10-16)
- v0.2.5 (2025-10-16)
- v0.2.4 (2025-10-16)
- v0.2.2 (2025-10-16)
- v0.2.1 (2025-10-15)
- v0.2.0 (2025-10-15)
- v0.1.2 (2025-10-15)
- v0.1.1 (2025-10-15)
- Development Setup Summary