Skip to main content

The text wizard - Transform text files with pluggable extensions

Project description

gtext Logo

🪄 gtext

The text wizard - Transform text files with pluggable extensions.

PyPI version Tests codecov Python 3.10+ License: MIT Documentation


✨ What is gtext?

gtext is a universal text processor with a pluggable extension system. Transform any text file through customizable plugins:

  • 📝 Include files (static, dynamic, glob patterns)
  • 🤖 AI processing (summarization, translation)
  • 💻 Code generation (headers, boilerplate)
  • Validation (links, spelling)
  • 🔄 And much more...

Created by the Genro Team. Universal and standalone.


🚀 Quick Start

Installation

pip install gtext

Basic Usage

File Extension Convention

gtext uses the .gtext extension to identify source files:

# Double extension (auto-detect output format)
document.md.gtext   document.md
script.py.gtext     script.py
config.yaml.gtext   config.yaml

Example

Source file (report.md.gtext):

# Monthly Report

## Company Stats

```include
cli: python scripts/get_stats.py --format markdown
```

## Team Structure

```include
docs/team-structure.md
```

## All Project Docs

```include
glob: projects/**/README.md
```

Generate expanded document:

# Auto-detect output (strip .gtext extension)
gtext render report.md.gtext

# Or specify output file/directory
gtext render report.md.gtext report.md
gtext render report.md.gtext output/

# Process multiple files or patterns
gtext render "docs/**/*.gtext" output/

Re-render after changes (using saved metadata):

# Modify report.md.gtext, then refresh
gtext refresh report.md.gtext

# Or refresh all .gtext files with saved outputs
gtext refresh

Result (report.md):

# Monthly Report

## Company Stats

| Metric | Value |
|--------|-------|
| Revenue | $1.2M |
| Users | 10,453 |

## Team Structure

[content from docs/team-structure.md]

## All Project Docs

[all README.md files from projects/**/]

🆕 New in v0.2.0: The render command now intelligently handles single files, multiple files, and patterns. The old cast and cast-all commands are deprecated (but still work) and will be removed in v0.3.0.


📓 Learning with Interactive Tutorials

The best way to learn gtext is through our hands-on Jupyter notebooks.

Run Online (No Installation Required)

Binder

Click the badge above to launch an interactive Jupyter environment in your browser. Ready in ~2 minutes!

Run Locally

# 1. Install Jupyter
pip install jupyter notebook

# 2. Navigate to notebooks directory
cd notebooks

# 3. Launch Jupyter
jupyter notebook

# 4. Open 01_rag_prompt_engineering.ipynb and start learning!

Tutorial Contents

Notebook Topic Duration Level
01 - RAG & Prompt Engineering AI/LLM integration, composable prompts 30 min Intermediate

More tutorials coming soon! See notebooks/README.md for the complete learning guide.


🎯 Key Features

1. Include Static Files

```include
path/to/file.md

### 2. Include Command Output

```markdown
```include
cli: genro project list --format markdown

### 3. Include Multiple Files with Glob

```markdown
```include
glob: docs/**/*.md

### 4. Mix All Types

```markdown
```include
header.md
cli: python get_stats.py
glob: sections/*.md
footer.md

---

## 📚 Use Cases

### Documentation

- **Living docs** that update from real data
- **Multi-file documentation** aggregation
- **Auto-generated API docs** from code

### Code Management

- **License headers** across codebase
- **Boilerplate injection**
- **Shared imports** and configs

### Reporting

- **Dynamic reports** with live database queries
- **System monitoring** snapshots
- **Business dashboards** in Markdown

### Content Management

- **Blog post templates** with includes
- **Multi-language content**
- **Reusable content blocks**

---

## 🛠️ CLI Commands

```bash
# Expand single file (auto-detect output)
gtext cast document.md.gtext

# Explicit output path
gtext cast document.md.gtext -o output.md

# Expand all .gtext files in directory
gtext cast-all docs/**/*.gtext

# Watch mode (auto-regenerate on changes)
gtext watch docs/**/*.gtext

# Dry run (preview without writing)
gtext cast document.md.gtext --dry-run

🔌 Plugin System

gtext is built on a pluggable architecture. Extensions are easy to create:

from gtext.extensions import BaseExtension

class MyExtension(BaseExtension):
    name = "my-plugin"

    def process(self, content: str, context: dict) -> str:
        # Your transformation logic
        return transformed_content

Built-in extensions:

  • include - Include static files
  • include-cli - Include command output
  • include-glob - Include files matching patterns

Future extensions:

  • ai-summarize - AI-powered summarization
  • ai-translate - Multi-language translation
  • validate-links - Check for broken links
  • generate-toc - Auto table of contents
  • And more...

📖 Documentation

Full documentation available at: gtext.readthedocs.io


🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.


📜 License

MIT License - see LICENSE for details.


🌟 About

gtext is created by Giovanni Porcari with contributions from the Genro Team.

Like a weaverbird 🪶 that masterfully weaves materials together, gtext weaves different content sources into unified documents.

gtext is:

  • Standalone - No dependencies on other frameworks
  • Universal - Works with any text format
  • Open - MIT licensed and community-driven

🔗 Links


Made with ✨ by the Genro Team

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

gtext-0.2.0.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

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

gtext-0.2.0-py3-none-any.whl (20.6 kB view details)

Uploaded Python 3

File details

Details for the file gtext-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for gtext-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2880f316f3d7c7636060c08afefd4fba5f200e167866aa2d9a2ced80592d5c7c
MD5 25975a5951129c1622891d8c296c1828
BLAKE2b-256 36ba4969909a184c1dd47c07d31a4ef464820cf3ed5679b027e9ed6b9caab262

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtext-0.2.0.tar.gz:

Publisher: publish.yml on genropy/gtext

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

File details

Details for the file gtext-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for gtext-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4243609333ade5ee7c0ed8f3f2318964cda9f179b4b3cc2a296c1fcacdf0f7b7
MD5 d2663b53990441ec55ca2295d0635b9b
BLAKE2b-256 16f085baff2ef52cb8e4bca3987703a20305bed5642af54f023d179823ffba41

See more details on using hashes here.

Provenance

The following attestation bundles were made for gtext-0.2.0-py3-none-any.whl:

Publisher: publish.yml on genropy/gtext

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