Skip to main content

A modern async Wikipedia API client

Project description

Modern Wikipedia API Client

A async Wikipedia API client with advanced features for professional use.

Features

  • Async/Await Support: Built with aiohttp for high-performance async operations
  • Automatic Rate Limiting: Configurable rate limiting with smart backoff
  • Retry Logic: Exponential backoff with jitter for robust error handling
  • Caching: Time-based caching with TTL support
  • Multi-language Support: Easy language switching
  • Batch Operations: Optimized batch requests for multiple pages
  • Type Safety: Full type annotations with Pydantic models
  • Error Handling: Comprehensive error hierarchy
  • Production Ready: Optimal defaults for production use

Quick Start

Installation

pip install wikipedia-async
import asyncio
from wikipedia_async import WikipediaClient

async def main():
    # Initialize client with optimal defaults
    client = WikipediaClient()

    # Search for articles
    res = await client.search("Python programming")
    results = res.results
    print(f"Found {len(results)} search results:")

    # Get page content
    page = await client.get_page("Python (programming language)") # url or title
    print(f"Title: {page.title}")
    print(f"Summary: {page.summary[:200]}...")

    # Sections (table supported)
    print("Sections:")
    for section in page.sections:
        print(section.to_string(markdown=True))

    # if tables don't show set get_page(include_tables=True) to explicitly get tables (which is slower)

    # Batch operations
    res = await client.get_pages_batch(["Python", "JavaScript", "Rust"]) # list of titles or urls
    for p in res.successful:
        print(f"- {p.title} ({p.url})")
    for err in res.failed:
        print(err)

    await client.close()

if __name__ == "__main__":
    asyncio.run(main())

Configuration

from wikipedia_async import WikipediaClient, ClientConfig

config = ClientConfig(
    language="en",
    rate_limit_calls=10,
    rate_limit_period=1.0,
    max_retries=3,
    cache_ttl=300,  # 5 minutes
    timeout=30.0,
    max_concurrent_requests=10
)

client = WikipediaClient(config=config)

See Docs Here

Note: The documentation is outdated

See Examples Here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wikipedia_async-0.15.0.tar.gz (120.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wikipedia_async-0.15.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file wikipedia_async-0.15.0.tar.gz.

File metadata

  • Download URL: wikipedia_async-0.15.0.tar.gz
  • Upload date:
  • Size: 120.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for wikipedia_async-0.15.0.tar.gz
Algorithm Hash digest
SHA256 a0ab552dbe911fbcefc2180a14ea73aa569ac08b09215f2746af2943c9adebb7
MD5 afa3eaf2d3b7acb9c1c5e661a66ea04b
BLAKE2b-256 51c889aa1187369ebfd2b1c448974577af9aa18ec0a870eda1486f81ce8fe39c

See more details on using hashes here.

File details

Details for the file wikipedia_async-0.15.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wikipedia_async-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3a691a180caf5b7732fd7b0b99702de5c1071bb72b9ca7ebae73abce1b3f194
MD5 be5cb9c6d39d2ca02ffef6162917eb94
BLAKE2b-256 c5290381e3277682fa3800da3f4cb031a1cb2155f72564f6f95b3a1de0090ed2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page