Skip to main content

Command-line tool for retrieving and translating short quotes from classical Chinese texts via the Chinese Text Project (ctext.org) API.

Project description

━━━━━━━━━━━━━━━━━━━━━━━━━━━ ♉︎ T A O W | 3 D 3 Q 3 ━━━━━━━━━━━━━━━━━━━━━━━━━━━

♛ chtext

Classical Chinese Quote Generator created by 3D3Q3

CI PyPI Python License: MIT

⚡️ Objective

A command-line gateway to antiquity. chtext distills millennia of philosophical insight into short, quotable English translations from classical Chinese texts, delivering them directly to your terminal. Powered by the Chinese Text Project API, it parses dense historical paragraphs to extract concise, impactful wisdom. Useful, straightforward, and timeless.

$ chtext generate
"Knowing the male and guarding the female are the streams of the world."
  -- Dao De Jing (道德經), 道德經

📐 Core Features

  • Short quote generator - Extracts concise 1-3 sentence passages, not long paragraphs
  • English-first output - Translations via Google Translate, with optional Chinese metadata
  • 19 classical texts - Analects, Dao De Jing, Mengzi, Mozi, Art of War, and more
  • Duplicate tracking - SQLite-backed history so you never see the same quote twice
  • Batch export - Generate dozens of quotes to a file in one command
  • Multiple formats - Plain text, JSON, or full annotated output
  • Cross-platform - Works on macOS, Linux, and Windows

Installation

pip (recommended)

pip install chtext

Or install the latest development version directly from GitHub:

pip install git+https://github.com/3D3Q3/chtext.git

After installation the chtext command is available globally.

From source

git clone https://github.com/3D3Q3/chtext.git
cd chtext
pip install .

Without installing

git clone https://github.com/3D3Q3/chtext.git
cd chtext
pip install requests deep-translator
python -m chtext generate

Quick Start

# Get a short English quote from a random classical text
chtext generate

# Quote from a specific book
chtext generate --book dao-de-jing

# Include the original Chinese text
chtext generate --with-chinese

# Generate 20 quotes and save to a file
chtext generate --count 20 --output quotes.txt

# Output as JSON
chtext generate --format json

# See all available books
chtext list

Commands

Command Description
generate Generate short English quotes (the main feature)
random Get a random full paragraph with translation
unique Get a full paragraph you haven't seen before
batch Export multiple full paragraphs to a file
list List all available books
search Search texts by Chinese keyword
browse Explore a book's chapter structure
download Download a complete text to a file
stats View your quote history
status Check API connection and rate limits
config Manage API key and preferences

generate

The primary command. Fetches passages from the ctext.org API, splits long paragraphs into individual sentences, filters for short quotable passages, and translates them to English.

# Single quote
chtext generate

# From a specific book
chtext generate --book analects

# Batch to file
chtext generate --count 50 --output my_quotes.txt

# With Chinese text shown below each translation
chtext generate --count 10 --with-chinese

# JSON output (useful for programmatic consumption)
chtext generate --format json

config

# View current settings
chtext config --show

# Set an API key to unlock all books
chtext config --set-apikey YOUR_KEY

# Use simplified Chinese characters
chtext config --set-remap gb

# Set default book for random/generate
chtext config --set-default-book analects

Available Books

Five classical texts are available without an API key:

Key Text
analects The Analects (論語)
mengzi Mengzi (孟子)
dao-de-jing Dao De Jing (道德經)
mozi Mozi (墨子)
book-of-poetry Book of Poetry (詩經)

With a ctext.org API key, 14 additional texts are unlocked including Zhuangzi, Art of War, Han Feizi, Book of Rites, Records of the Grand Historian, and more. Run chtext list for the full catalog.

API Key

The tool works immediately without any API key. The free tier gives access to five major texts, which contain thousands of quotable passages.

For access to the full library:

  1. Visit ctext.org/tools/subscribe
  2. Register for an API key
  3. Set it: chtext config --set-apikey YOUR_KEY

How It Works

  1. Fetches text data from the ctext.org API
  2. Navigates book structure (books → chapters → paragraphs)
  3. Splits long paragraphs into sentences using Chinese punctuation boundaries (。!?)
  4. Filters for short, quotable passages (under ~80 characters)
  5. Translates to English via Google Translate
  6. Tracks seen quotes in a local SQLite database to avoid duplicates

Known Limitations

  • Translation stability - English output uses Google Translate via an unofficial interface (deep-translator). It can rate-limit or change without notice. If translation fails, the original Chinese text is still retrievable.
  • API rate limits - ctext.org enforces request limits; chtext spaces requests automatically, but large --count batches take time by design.

Requirements

  • Python 3.9+
  • Internet connection (for the ctext.org API and Google Translate)

License

This tool's source code is released under the MIT License.

Important: The classical Chinese texts retrieved through this tool come from the Chinese Text Project and are licensed under CC BY-NC-SA 3.0. This means the text content:

  • Requires attribution to ctext.org
  • May only be used for non-commercial purposes
  • Must be shared under the same license if redistributed

See the LICENSE file for full details on both the code and data licenses.

Acknowledgments

━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3 D 3 Q 3 | 2 0 2 6 ♛ ━━━━━━━━━━━━━━━━━━━━━━━━━━━

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

chtext-1.1.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

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

chtext-1.1.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file chtext-1.1.0.tar.gz.

File metadata

  • Download URL: chtext-1.1.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chtext-1.1.0.tar.gz
Algorithm Hash digest
SHA256 fc318c1317ffaf20af03e5f76d732972389e93949ae5deb9369f69f635e86724
MD5 e65f38b7ab2e85f4f4120f9689c6c7f7
BLAKE2b-256 668fc33bb2eb7f37460f07ac234a4ed3c474d07b21814955fec972421cf6161f

See more details on using hashes here.

Provenance

The following attestation bundles were made for chtext-1.1.0.tar.gz:

Publisher: python-publish.yml on 3D3Q3/chtext

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

File details

Details for the file chtext-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: chtext-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for chtext-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6fee219f0f956be5dc8c29722c1fbef2ae0ec0a5ed76530ca3485d168c3d752
MD5 dd0b9b127e3719fc70c39637004c182e
BLAKE2b-256 3ca94a0baae91ce2459d9fdd2239c4fccca25c9536f936461f09652a8bdba2d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for chtext-1.1.0-py3-none-any.whl:

Publisher: python-publish.yml on 3D3Q3/chtext

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