codapi: Interactive code examples

2 min read Original article ↗

for all types of technical writing

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

def greet(name):
  print(f"Hello, {name}!")

greet("World")

const greet = (name: string) => {
  console.log(`Hello, ${name}!`)
}

greet("World")

create table data(message text);
insert into data values ('Hello, World!');
select * from data;

greet() {
  echo "Hello, $1!"
}

greet "World"

#include <stdio.h>

void greet(const char* name) {
    printf("Hello, %s!\n", name);
}

int main() {
    greet("World");
}

and many more!

Increase product adoption — allow developers to interact with your software in tutorials and how-tos.
Make education more effective — add interactive exercises to your courses.
Engage readers — embed live code examples in your articles and blog posts.
Learn how Codapi is different

Playground

Codapi is not limited to the boring run command. You can lint, test and benchmark code, or run custom commands.

Codapi goes beyond a fixed set of programming languages and tools. Build your own playgrounds with custom packages and software, and use them for fun and profit.

FROM python:3.12-slim

COPY requirements.txt /tmp
RUN pip install -r /tmp/requirements.txt
COPY *.py /opt

RUN adduser --home /sandbox sandbox

USER sandbox
WORKDIR /sandbox

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

Use templates and multi-file playgrounds to focus on the important parts of the code and hide the rest behind the scenes.

Visualize data and model code dependencies to give readers a rich, Jupyter notebook-like experience.

Sample chart

Codapi is specifically designed for embedding in articles, product documentation, online courses, mobile apps, etc. — so it's very lightweight.

Integrate via JavaScript widget

<!-- code snippet -->
<pre>print("Hello, World!")</pre>

<!-- playground widget attaches to the previous snippet -->
<codapi-snippet sandbox="python" editor="basic">
</codapi-snippet>

<!-- playground script -->
<script src="https://unpkg.com/@antonz/codapi/dist/snippet.js">
</script>

Call the API

POST https://api.codapi.org/v1/exec
authorization: bearer ***
content-type: application/json

{
    "sandbox": "python",
    "command": "run",
    "files": {
        "": "print(\"hello world\")"
    }
}

Get started

Some playgrounds work entirely in the browser. Others require a Codapi server — available as a cloud service and as a self-hosted version.

Codapi cloud is free to try, no sign up required. If you exceed 1000 code runs/month, buy a subscription to extend the limit.

To set up custom sandboxes, use the self-hosted version. It's free and open-source.

Buy for $5/month  or try for free

Codapi is licensed under the permissive Apache-2.0 license and is committed to remaining open source forever.

There is also commercial support and a cloud version for those who prefer not to self-host.

Source code