skillfed

cogapp

Cog: A content generator for executing Python snippets in source files.

cogapp v3.6.0 253.5K downloads/30d#8,516 on PyPI408
Permissive license MIT Active released

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 cogapp

uv

uv add cogapp

poetry

poetry add cogapp

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Software Development :: Code Generators

Tags

code generation from python snippetsdynamic content in static filesembedded python executiontemplate-like code generationsource file content generationpython snippet processorstatic file templating
code-generationstatic-site-toolsdocumentation

More Code Generators packages