Skip to main content

CLI tool to download and save articles from various web resources into Markdown, Text, and other formats.

Project description

PyStates

A lightweight, elegant Python CLI tool for fetching clean, distraction-free web articles.

Python License: MIT Trafilatura

---

๐Ÿ“– Description

PyStates is a fast, minimalist command-line utility that downloads full-length articles from major publications (The New Yorker, Wired, The Atlantic, and hundreds more) and extracts clean, readable text using the industry-leading Trafilatura library.

It automatically removes ads, navigation menus, sidebars, comments, and boilerplate, then saves the result as either beautifully formatted Markdown (.md) or clean Plain Text (.txt).

Designed for researchers, writers, journalists, students, and power users who want to archive high-quality content locally โ€” without distractions or paywalls interfering with readability.

pystates -u https://www.newyorker.com/magazine/2025/01/20/the-new-ai-era

โœจ Features

  • ๐Ÿš€ Blazing Fast โ€” Downloads and processes articles in under 3 seconds
  • ๐Ÿ›ก๏ธ 403 Bypass โ€” Smart custom User-Agent headers to reliably avoid common blocks
  • ๐Ÿงผ Pristine Extraction โ€” Powered by Trafilatura for the cleanest possible text
  • ๐Ÿ“ Dual Format Support โ€” Native .md (with headings, emphasis, and structure) or .txt
  • ๐Ÿงน Intelligent Filename Sanitization โ€” Generates safe OS filenames from article titles without using re
  • โœ๏ธ Custom Filenames โ€” Override auto-generated names with the -o flag
  • ๐Ÿ Modern Python Stack โ€” Built for Python 3.10+ with clean architecture
  • ๐Ÿ“ฆ One-Command Installation โ€” pip install -e . for instant local development
  • ๐ŸŒ Broad Compatibility โ€” Works with virtually any news, magazine, or blog site supported by Trafilatura

๐Ÿš€ Installation (Local Dev Mode)

# 1. Clone the repository
git clone https://github.com/your-org/pystates.git
cd pystates

# 2. Install in editable/development mode
pip install -e .

Verify Installation

pystates --help

Requirements

  • Python โ‰ฅ 3.10
  • pip

All dependencies (requests, trafilatura, argparse) are automatically installed via pyproject.toml.

๐Ÿ–ฅ๏ธ Usage

Command Syntax

pystates -u URL [OPTIONS]

CLI Flags

Short Long Required Default Description
-u --url Yes โ€” The full URL of the article to fetch and process
-f --format No md Output format. Accepted values: md or txt
-o --output No (auto) Custom output filename without extension. If omitted, a sanitized version of the article title is used

Examples

1. Basic usage (Markdown, auto-generated filename)

pystates -u "https://www.newyorker.com/magazine/2025/01/20/the-new-ai-era"

โ†’ Creates the-new-ai-era.md

2. Save as plain text

pystates -u "https://www.wired.com/story/the-future-of-coding/" -f txt

โ†’ Creates the-future-of-coding.txt

3. Custom output filename

pystates -u "https://www.theatlantic.com/ideas/archive/2025/07/climate-change/" \
         -o "climate_report_july_2025" \
         -f md

โ†’ Creates climate_report_july_2025.md

4. Full-featured command

pystates \
  --url "https://www.newyorker.com/culture/cultural-comment/the-end-of-the-internet-as-we-know-it" \
  --format txt \
  --output "end_of_internet"

5. View all options

pystates --help

Sample Output (Markdown)

# The New AI Era

**By Jane Smith**  
*Published: January 20, 2025*  
*Source: The New Yorker*

---

Artificial intelligence is no longer a distant promise...

## A New Paradigm

The implications are profound...

๐Ÿ“ Project Structure

PyStates/
โ”œโ”€โ”€ pystates/
โ”‚   โ”œโ”€โ”€ __init__.py          # Package metadata & version
โ”‚   โ”œโ”€โ”€ __main__.py          # Entry point for `python -m pystates`
โ”‚   โ”œโ”€โ”€ cli.py               # Argument parsing (argparse)
โ”‚   โ”œโ”€โ”€ exporters.py         # Filename sanitization + .md/.txt formatting
โ”‚   โ””โ”€โ”€ parser.py            # HTTP fetching (custom UA) + Trafilatura parsing
โ”œโ”€โ”€ pyproject.toml           # Modern packaging + entry points
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

๐Ÿ“œ License

This project is released under the MIT License.

See LICENSE for the full text.


PyStates โ€” preserving the web's best writing, one clean file at a time.

Built with care by the open-source community.

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

pystates_cli-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

pystates_cli-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pystates_cli-0.1.0.tar.gz.

File metadata

  • Download URL: pystates_cli-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for pystates_cli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 721c11c6eb78e8b4496f34f15a49ae5f7ba77f944ad7f3d9f72ca83b5b64c9c5
MD5 379be125fc073ef25cbf9d800c406511
BLAKE2b-256 96795f15cc5c6f955290d8ae585002ddee2cc35222ed267e61143589831c337a

See more details on using hashes here.

File details

Details for the file pystates_cli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pystates_cli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for pystates_cli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25f8622b3a972a77bfad7fdd8f2a0a10c291a2e43b1d6e266d6b0d5a7d3a6e1c
MD5 4406fbad8f1225d2793ed09c9d68c156
BLAKE2b-256 f600281d944d86f1879a9fcd24f044ad705f9010d0973773bb10d817c1e5dec7

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