cogapp
Cog: A content generator for executing Python snippets in source files.
What it is and what it does
Cog is a content generator that finds Python code blocks marked in source files, executes them, and replaces the marked regions with their output. It's designed for static files—documentation, HTML, configuration, or any text format—where you want computed or templated content without a full build system. The tool reads the source, runs the embedded Python, and writes the result back in place.
It has no external runtime dependencies and runs on Python 3.9 and later. The workflow is straightforward: mark a code block with special comments, run the tool on the file, and the output replaces the marked section. This is useful for keeping generated content (like tables, API docs, or configuration examples) in sync with the code that produces them, without requiring a separate templating language or build step.
Use it for:
- Keep API documentation examples in sync by embedding Python code that generates them.
- Generate configuration file snippets or boilerplate from Python logic.
- Maintain data tables or reference lists in markdown by computing them from live data.
- Embed test output or validation results directly into README or guide files.
- Generate HTML or XML fragments from Python without a full template engine.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Cog executes Python code snippets embedded in source files and replaces them with their output, enabling dynamic content generation in static files.
Yes. Cog is lightweight, actively maintained, has no dependencies, and solves a specific problem well: keeping computed content in sync with its source code. Install it if you need to embed executable Python in static files and regenerate their output on demand. The MIT license and broad Python version support make it low-risk.
Install
cogapp on PyPI
pip
pip install cogappuv
uv add cogapppoetry
poetry add cogappInstalling cogapp
Before you install
Low friction: pure Python wheel with no runtime dependencies. Active maintenance with recent commits and stable production status across Python 3.9–3.14.
License in practice
MIT license permits commercial and private use with minimal restrictions; attribution required.
Quickstart
pip install cogapp
In a source file, mark a code block with special delimiters, then run cogapp to execute the embedded code and replace the marked section with its output.
Requires Python 3.9 or later.
Verify before relying
- Whether the package handles complex nested code generation or only simple linear snippets.
- Performance characteristics on large files or many embedded snippets.
- Integration patterns with common static site generators (Hugo, Jekyll, Sphinx).
- Exact syntax and delimiter format for marking code blocks in different file types.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 327 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 253,549/month — #8,516 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cogapp-3.6.0-py3-none-any.whl
Tags
More Code Generators packages
Proto Plus wraps protocol buffers to provide…
permissive · top 1,000 on PyPI
CythonCython is a source code translator that…
permissive · top 1,000 on PyPI
asttokensAnnotates Python abstract syntax trees with the…
permissive · top 1,000 on PyPI
beartypeBeartype is a runtime type checker that…
permissive · top 1,000 on PyPI
llvmlitellvmlite provides a lightweight Python binding…
permissive · top 1,000 on PyPI
astorastor converts Python abstract syntax trees…
permissive · top 5,000 on PyPI
markdown-execExecutes code blocks embedded in Markdown files…
permissive · top 5,000 on PyPI
cogCog packages machine learning models into…
permissive · top 5,000 on PyPI
ct3Cheetah3 is a template engine and code…
permissive · top 5,000 on PyPI
Cheetah3Cheetah3 is a template engine and code…
permissive · top 15,000 on PyPI
streamlit-embedcodeEmbeds code snippets from external services…
unclear · top 15,000 on PyPI
rio-cogeorio-cogeo creates and validates Cloud Optimized…
permissive · top 15,000 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
PyLaTeXPyLaTeX generates LaTeX documents and code…
permissive · top 15,000 on PyPI
html5taggerGenerates HTML5 markup programmatically using…
permissive · top 5,000 on PyPI
sybilSybil parses and executes code examples…
permissive · top 15,000 on PyPI