Skip to main content

Code-aware static site generator with directive-based content extraction

Project description

selfdoc

Code-aware static site generator that resolves directive blocks in Markdown templates into live content extracted from your source code.

Supports Python, Go, and TypeScript/JavaScript. Zero runtime dependencies -- pure Python stdlib.

Install

pip install selfdoc

or via npm (delegates to Python under the hood):

npm install -g selfdoc

Requires Python 3.11+.

Quick start

# Initialize in an existing project (auto-detects language)
selfdoc init

# Edit docs/index.md -- add directives referencing your code
# (see Directive syntax below)

# Build HTML output
selfdoc build

# Serve locally with live reload
selfdoc serve

Directive syntax

Directives are inline blocks in your Markdown templates. They get replaced with content extracted from your source code at build time.

:-: directive-name path="arg"

Self-closing directives use :-:. Block directives that wrap a body use :<: to open, :>: to close, with :=: and ::: to delimit sections inside. Directives inside fenced code blocks are ignored.

Built-in directives

Directive Attributes Description
ref path Extract module/package docstrings, exported functions, classes
table-schema path, target Extract dataclass fields or JSON keys as a table
code-test path, target Embed test source code (whole file or specific function/class)
code-help path Extract CLI help/usage text and flag definitions
table-config path Render JSON/TOML config files as key-value tables

Example -- embed the API docs for a Python module:

## API Reference

:-: ref path="selfdoc.config"

Example -- show a JSON schema as a table:

:-: table-schema path="selfdoc.json"

Custom directives

Register custom directives in selfdoc.json under the directives key. Each entry maps a directive name to a Python script (relative to project root) that exports a resolve(attrs, config, body) function returning a Markdown string.

{
  "directives": {
    "changelog": "scripts/changelog_directive.py"
  }
}

Script interface:

def resolve(attrs: dict, config: dict, body: list) -> str:
    """Return Markdown string to replace the directive block.

    attrs  -- directive attributes as str->str dict (e.g. {"path": "v1.0.0"})
    config -- the full selfdoc.json config dict
    body   -- body lines from the directive block (empty list for one-liners)
    """
    version = attrs.get("path")
    ...

Use in templates:

:-: changelog path="v1.0.0"

Custom directives take priority over built-in names.

Configuration

selfdoc.json at the project root:

{
  "language": "python",
  "source": ["selfdoc/"],
  "docs": "docs/",
  "output": "docs/_build/",
  "deploy": {
    "provider": "cloudflare-pages",
    "project": "my-docs"
  },
  "directives": {}
}
Field Required Default Description
language yes -- python, go, typescript, or javascript
source yes -- List of source directories to scan
docs no docs/ Directory containing Markdown templates
output no docs/_build/ Directory for generated HTML output
deploy no -- Deploy provider config (see Deploy below)
directives no {} Custom directive script mappings

selfdoc init auto-detects language and source paths from project files (pyproject.toml, go.mod, tsconfig.json, package.json).

Commands

Command Description
selfdoc init Initialize selfdoc in the current project (creates selfdoc.json + starter template)
selfdoc build Resolve directives and generate HTML to the output directory
selfdoc serve [--port PORT] Serve built docs locally with SSE-based live reload (default port 8000)
selfdoc deploy Deploy docs to the configured provider
selfdoc check Validate all directives resolve successfully; report documentation coverage

Deploy

Cloudflare Pages

Requires the Wrangler CLI installed and authenticated.

{
  "deploy": {
    "provider": "cloudflare-pages",
    "project": "my-docs-project"
  }
}
selfdoc build && selfdoc deploy

GitHub Pages

Pushes the output directory to the gh-pages branch via force-push.

{
  "deploy": {
    "provider": "github-pages"
  }
}

Enable GitHub Pages in your repo settings (source: gh-pages branch).

Integration with rlsbl

When rlsbl detects a selfdoc.json in the project, it can trigger selfdoc build and selfdoc deploy as part of the release lifecycle via the .rlsbl/hooks/post-release.sh hook.

License

MIT

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

selfdoc-0.5.1.tar.gz (390.5 kB view details)

Uploaded Source

Built Distribution

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

selfdoc-0.5.1-py3-none-any.whl (152.0 kB view details)

Uploaded Python 3

File details

Details for the file selfdoc-0.5.1.tar.gz.

File metadata

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

File hashes

Hashes for selfdoc-0.5.1.tar.gz
Algorithm Hash digest
SHA256 6da4774891ead9adfd92530efcfed253af375c7a96ab9181a66a1b213e0d2b64
MD5 18cf3f473ed5461ed619aa6d056b5c35
BLAKE2b-256 318c25685c26aaeccc6ab276bf1c05aedf40d5af93050b4284cde6c51452f45c

See more details on using hashes here.

Provenance

The following attestation bundles were made for selfdoc-0.5.1.tar.gz:

Publisher: publish.yml on smm-h/selfdoc

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

File details

Details for the file selfdoc-0.5.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for selfdoc-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31a7f331ba7bf5a7238593a5c7121ada9f60a665164534de3f11017f78fc3ca9
MD5 300368ba7a9687db4be84d03ea7c0587
BLAKE2b-256 f84eb3db80896695efb7a3fc9a8053184e4015d4061c8b28f0ea9fcf49b6e531

See more details on using hashes here.

Provenance

The following attestation bundles were made for selfdoc-0.5.1-py3-none-any.whl:

Publisher: publish.yml on smm-h/selfdoc

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