Skip to content

feat: Introduce Sync and Async Clients - #479

Merged
martin-majlis merged 27 commits into
masterfrom
2026-03-14-migrate-to-httpx
Mar 16, 2026
Merged

martin-majlis merged 27 commits into
masterfrom
2026-03-14-migrate-to-httpx

Conversation

@martin-majlis

@martin-majlis martin-majlis commented Mar 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR introduces asynchronous support to the Wikipedia-API library, providing a complete async/await interface alongside the existing synchronous API. The migration includes a major architectural refactoring to separate HTTP transport concerns from API logic, enabling cleaner code organization and better maintainability.

Key Changes

🚀 New Async API

  • AsyncWikipedia and AsyncWikipediaPage classes with full async/await support
  • Perfect symmetry between sync and async APIs - every method/property has corresponding async version
  • New examples: example_async.py and updated example_sync.py

🏗️ Architecture Refactoring

  • Transport layer separation: HTTP client logic moved to _http_client.py
  • API layer abstraction: MediaWiki API logic centralized in _resources.py
  • Base classes: Shared functionality extracted to _base_wikipedia_page.py
  • Multiple inheritance: Clean composition of transport + API mixins

📦 Dependencies & Tooling

  • Migration to httpx: Modern HTTP client replacing requests
  • New dependency management: pyproject.toml with uv package manager
  • Enhanced testing: Comprehensive async test coverage
  • Documentation updates: Complete API reference and design documentation

🧪 Testing & Quality

  • 90%+ code coverage maintained across all modules
  • Async test suites: Full coverage for new async functionality
  • CLI test updates: Updated snapshots with current Wikipedia data
  • Pre-commit hooks: Enhanced code quality checks

Files Changed

  • 48 files modified with 6,245 additions and 1,459 deletions
  • Core library files restructured for better separation of concerns
  • Comprehensive test coverage for both sync and async APIs
  • Updated documentation and examples

Breaking Changes

  • Python 3.10+ required (was previously 3.8+)
  • httpx replaces requests as HTTP client dependency
  • uv package manager added for development workflow

Migration Guide

Existing synchronous code remains unchanged:

# Sync (unchanged)
wiki = wikipediaapi.Wikipedia('en')
page = wiki.page('Python')
print(page.summary)

New async usage:

# Async (new)
wiki = wikipediaapi.AsyncWikipedia('en')
page = await wiki.page('Python')
print(await page.summary)

Testing

  • All existing tests pass
  • New async test suites provide comprehensive coverage
  • CLI tests updated with current Wikipedia data
  • Code coverage maintained above 90%

This migration positions Wikipedia-API for modern Python development while maintaining full backward compatibility for existing users.

@codecov

codecov Bot commented Mar 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.94406% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.15%. Comparing base (cfe442f) to head (b9bec3e).
⚠️ Report is 127 commits behind head on master.

Files with missing lines Patch % Lines
wikipediaapi/_resources.py 95.88% 10 Missing ⚠️
wikipediaapi/_base_wikipedia_page.py 86.15% 9 Missing ⚠️
wikipediaapi/wikipedia_page.py 94.38% 5 Missing ⚠️
wikipediaapi/async_wikipedia_page.py 97.35% 4 Missing ⚠️
wikipediaapi/_http_client.py 99.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #479      +/-   ##
==========================================
- Coverage   98.79%   97.15%   -1.64%     
==========================================
  Files           9       14       +5     
  Lines         832     1197     +365     
==========================================
+ Hits          822     1163     +341     
- Misses         10       34      +24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@martin-majlis
martin-majlis force-pushed the 2026-03-14-migrate-to-httpx branch from b552236 to f4ecc9b Compare March 15, 2026 21:45
@martin-majlis
martin-majlis merged commit f1ff681 into master Mar 16, 2026
38 of 41 checks passed
@martin-majlis
martin-majlis deleted the 2026-03-14-migrate-to-httpx branch March 16, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant