Skip to main content

A CLI tool to fetch Wikipedia articles

Project description

wiki-client

PyPI Version Python Versions

A command-line tool to fetch Wikipedia articles and display them in the terminal.

Overview

wiki is a Python CLI that retrieves Wikipedia articles via the Wikipedia REST API and renders them with Rich for a beautiful terminal experience.

Features

  • Fetch articles — Query Wikipedia by article title or search query
  • Search mode — Show a ranked list of search results
  • Raw output — Print plain text instead of Rich-formatted output

Requirements

  • Python 3.10 or newer

The following Python packages are installed automatically:

Package Purpose
click CLI argument parsing
httpx HTTP requests to the Wikipedia API
rich Terminal formatting and rendering

Installation

Recommended: uvx (no permanent install required)

The easiest way to run wiki is with uvx from the uv toolkit. This downloads and runs the tool in an isolated environment without permanently installing it:

uvx --from wiki-client wiki "Unix shell"

Install uv (if you haven't already):

curl -LsSf https://astral.sh/uv/install.sh | sh

pip install (permanent install)

Installing via pip places the wiki command on your $PATH directly:

pip install wiki-client
wiki "Unix shell"

Install from source

git clone https://github.com/dsillman2000/wiki-client.git
cd wiki-client
pip install .
wiki "Unix shell"

Or use the provided install script:

curl -fsSL https://raw.githubusercontent.com/dsillman2000/wiki-client/main/install.sh | sh

Docker

A Docker image is available on GitHub Container Registry (GHCR) with all dependencies pre-installed:

# Pull the image
docker pull ghcr.io/dsillman2000/wiki-client:latest

# Run a query
docker run --rm ghcr.io/dsillman2000/wiki-client:latest "Unix shell"

# Extract specific section
docker run --rm ghcr.io/dsillman2000/wiki-client:latest -s History "Bash"

# List sections
docker run --rm ghcr.io/dsillman2000/wiki-client:latest --ls "Python"

# Save output to file (mount current directory)
docker run --rm -v "$(pwd)":/home/wiki ghcr.io/dsillman2000/wiki-client:latest \
  "Operating system" -o os.md

Advantages:

  • No local dependency installation required
  • Consistent environment across systems
  • Easy integration into CI/CD pipelines
  • Lightweight multi-stage build (~218MB)

Usage

Basic Queries

# Fetch an article
wiki "Unix shell"

# Print plain text (no Rich formatting)
wiki "Unix shell" --raw

Search Mode

# Show search results instead of auto-fetching
wiki --search "shell programming"

Section Listing & Filtering

# List all sections in an article
wiki --list-sections "Unix shell"
wiki --ls "Unix shell"          # shorthand

# Extract a specific section (fuzzy match)
wiki -s History "Unix shell"
wiki -s "early" "Unix shell"    # matches "Early shells", "Early history", etc.

# Multiple sections
wiki -s History -s "See also" "Unix shell"

Version

wiki --version

Examples

# Get the Unix shell article
wiki "Unix shell"

# Search for shell-related articles
wiki --search "shell interpreters"

# Print raw text
wiki "Bash (Unix shell)" --raw

# List all sections
wiki --ls "Unix shell"

# Read the History section
wiki -s History "Unix shell"

Development

Quick Start

# Install in editable mode with dev dependencies
pip install -e .
pip install pytest pytest-httpx ruff

# Or use Make
make install-dev

Linting & Testing

make lint       # ruff + shellcheck + prettier
make lint-python  # ruff only
make test       # pytest

Or run directly:

ruff check wiki_client/ tests/
python -m pytest tests/ -v

Available Make Targets

make help           # Show all targets
make install        # pip install -e .
make install-dev    # Install dev dependencies
make lint           # Run all linting checks
make lint-python    # ruff
make lint-shell     # shellcheck
make lint-markdown  # prettier
make test           # pytest
make format         # prettier --write README.md
make clean          # Remove build artifacts

How It Works

  1. Query resolution — Tries a direct Wikipedia REST API title lookup; falls back to a full-text search if the title returns 404.
  2. Rendering — Uses Rich to render the article extract as formatted Markdown in the terminal. Pass --raw for plain-text output.

Version

1.0.0

License

MIT

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

wiki_client-1.6.0.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

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

wiki_client-1.6.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file wiki_client-1.6.0.tar.gz.

File metadata

  • Download URL: wiki_client-1.6.0.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wiki_client-1.6.0.tar.gz
Algorithm Hash digest
SHA256 2e23b8a2e7f92e28cb82c3c16331b42e387ac4c725e3c7b5c35b18ce18ecd8ae
MD5 2dbe9391ac8a9131b8ebabf06dd7f125
BLAKE2b-256 605f30c13ccd8d9f615c08612b1932faccfe3c51a27ea64bb1aa9ab0e5f7fc66

See more details on using hashes here.

Provenance

The following attestation bundles were made for wiki_client-1.6.0.tar.gz:

Publisher: release.yml on dsillman2000/wiki-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wiki_client-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: wiki_client-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wiki_client-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2765cf99b8c1378fbffb1acb4ce7b3c047080c677852dee71df5773e2e08fada
MD5 e0aeaaf16cf9caa29610ca59913dd933
BLAKE2b-256 f7f8d91a383db194d410f017e4363a032b6e7404de4eddce0fa59ecec128236d

See more details on using hashes here.

Provenance

The following attestation bundles were made for wiki_client-1.6.0-py3-none-any.whl:

Publisher: release.yml on dsillman2000/wiki-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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