@antonz/codapi

中文文档
0.20.1发布于 2026/08/21MIT零依赖近 30 天下载 2043

Interactive code examples for documentation, education and fun.

原始使用文档
文档目录6 节
  1. Installation
  2. Usage
  3. Advanced features
  4. In-browser playgrounds
  5. Styling
  6. Support

Interactive code examples

for documentation, education and fun 🎉

Embed interactive code snippets directly into your product documentation, online course or blog post.

┌───────────────────────────────┐
│ def greet(name):              │
│   print(f"Hello, {name}!")    │
│                               │
│ greet("World")                │
└───────────────────────────────┘
  Run ►  Edit  ✓ Done
┌───────────────────────────────┐
│ Hello, World!                 │
└───────────────────────────────┘

Highlights:

  • Automatically converts static code examples into mini-playgrounds.
  • Lightweight and easy to integrate.
  • Sandboxes for any programming language, database, or software.
  • Open source. Uses the permissive Apache-2.0 license.

For an introduction to Codapi, see this post: Interactive code examples for fun and profit.

Installation

Install with npm:

npm install @antonz/codapi

Or use a CDN:

<script src="https://unpkg.com/@antonz/[email protected]/dist/snippet.js"></script>

Optional styles:

<link rel="stylesheet" href="https://unpkg.com/@antonz/[email protected]/dist/snippet.css" />

Usage

See the guide that best fits your use case:

You'll also need a working Codapi server, either cloud-based at codapi.org or self-hosted. Unless you are using an in-browser playground (see below).

Advanced features

Codapi offers a number of features that go beyond simple code playgrounds:

In-browser playgrounds

Most playgrounds (like Go or PostgreSQL) run code on the Codapi server.

There are also two playgrounds that work completely in the browser, no Codapi server required — JavaScript and Fetch.

Styling

The widget is unstyled by default. Use snippet.css for some basic styling or add your own instead.

Here is the widget structure:

<codapi-snippet sandbox="python" editor="basic">
    <codapi-toolbar>
        <button>Run</button>
        <a href="#edit">Edit</a>
        <codapi-status> ✓ Done </codapi-status>
    </codapi-toolbar>
    <codapi-output>
        <pre><code>Hello, World!</code></pre>
    </codapi-output>
</codapi-snippet>

codapi-snippet is the top-level element. It contains the the toolbar (codapi-toolbar) and the code execution output (codapi-output). The toolbar contains a Run button, one or more action buttons (a) and a status bar (codapi-status).

Support

Codapi is mostly a one-man project, not backed by a VC fund or anything.

If you find Codapi useful, please star it on GitHub and spread the word among your peers. It really helps to move the project forward.

★ Subscribe to stay on top of new features.

版本与发布记录

@antonz/codapi 共发布 58 个版本,首次发布于 2023/08/17;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.20.1latest2026/08/212 个月前
0.20.02025/12/1310 个月前
0.19.102024/12/211.9 年前
0.19.92024/12/211.9 年前
0.19.82024/08/182 年前
0.19.72024/05/162 年前

其他发布通道:beta → 0.13.0-beta.1。

关于 @antonz/codapi 的常见问题

@antonz/codapi 是什么?

Interactive code examples for documentation, education and fun.

如何安装 @antonz/codapi?

在项目目录运行 npm install @antonz/codapi,或使用 pnpm add / yarn add / bun add。

@antonz/codapi 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/antonz__codapi 是否存在。

@antonz/codapi 可以商用吗?

@antonz/codapi 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@antonz/codapi 的下载量有多少?

根据 npm 官方下载统计,@antonz/codapi 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,043 次,日均约 68 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@antonz/codapi 还在维护吗?

最新版本 0.20.1 发布于 2026/08/21(2 个月前);至今共发布 58 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/08/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。