• Stars
    star
    677
  • Rank 64,126 (Top 2 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created 5 months ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive code examples for documentation, education and fun

Interactive code examples

for documentation, education and fun πŸŽ‰

Codapi is a platform for embedding 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!                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Codapi manages sandboxes (isolated execution environments) and provides an API to execute code in these sandboxes. It also provides a JavaScript widget codapi-js for easier integration.

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

See Installing Codapi for details.

Usage (API)

Call /v1/exec to run the code in a sandbox:

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

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

sandbox is the name of the pre-configured sandbox, and command is the name of a command supported by that sandbox. See Adding a sandbox for details on how to add a new sandbox.

files is a map, where the key is a filename and the value is its contents. When executing a single file, it should either be named as the command expects, or be an empty string (as in the example above).

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "python_run_9b7b1afd",
  "ok": true,
  "duration": 314,
  "stdout": "hello world\n",
  "stderr": ""
}
  • id is the unique execution identifier.
  • ok is true if the code executed without errors, or false otherwise.
  • duration is the execution time in milliseconds.
  • stdout is what the code printed to the standard output.
  • stderr is what the code printed to the standard error, or a compiler/os error (if any).

Usage (JavaScript)

See codapi-js to embed the JavaScript widget into a web page. The widget uses exactly the same API as described above.

Contributing

Contributions are welcome. For anything other than bugfixes, please first open an issue to discuss what you want to change.

Be sure to add or update tests as appropriate.

License

Copyright 2023 Anton Zhiyanov.

The software is available under the Apache-2.0 license.

Stay tuned

β˜… Subscribe to stay on top of new features.

More Repositories

1

sqlean

The ultimate set of SQLite extensions
C
3,306
star
2

sqlime

Online SQLite playground
JavaScript
583
star
3

dataviz

Data visualization guide for presentations, reports, and dashboards
Python
428
star
4

codapi-js

Interactive code examples for documentation, education and fun.
JavaScript
396
star
5

pokitoki

Humble ChatGPT Telegram Bot
Python
288
star
6

sqlpkg-cli

SQLite package manager
Go
160
star
7

iuliia-py

Transliterate Cyrillic β†’ Latin in every possible way
Python
109
star
8

zero

Zero Dependency Club
104
star
9

sqlpkg

SQLite extension registry
101
star
10

sqlean.py

Python's sqlite3 + extensions
C
91
star
11

iuliia-js

Transliterate Cyrillic β†’ Latin in every possible way
TypeScript
79
star
12

podsearch-py

Let's find some podcasts!
Python
70
star
13

iuliia

Transliterate Cyrillic β†’ Latin in every possible way
67
star
14

sqlite

SQLite / Sqlean shell builds
Makefile
57
star
15

sqlean.js

Browser-based SQLite with extensions
Makefile
48
star
16

whatbrowser

ВсС, Ρ‡Ρ‚ΠΎ Π½ΡƒΠΆΠ½ΠΎ Π·Π½Π°Ρ‚ΡŒ ΠΎ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ
JavaScript
43
star
17

invoice

Ну ΠΎΡ‡Π΅Π½ΡŒ простоС выставлСниС счСтов для ΡŽΡ€Π»ΠΈΡ†
HTML
39
star
18

words

Word and phrase lists in CSV
Python
25
star
19

tryxinyminutes

Live code tutorials in your browser
C
15
star
20

metro

Metro lines and stations for cities in Belorussia, Kazakhstan, Russia and Ukraine
13
star
21

sqlite-stats

Statistical functions for SQLite
C
9
star
22

metalsmith-typography

A Metalsmith plugin to enhance typography
JavaScript
9
star
23

php-wasi

PHP WASI build.
JavaScript
8
star
24

sqlite-wasi

SQLite WASI build.
C
7
star
25

sqliter

SQLite Π½Π° ΠΏΡ€Π°ΠΊΡ‚ΠΈΠΊΠ΅
JavaScript
6
star
26

python-wasi

Python WASI build.
JavaScript
6
star
27

lua-wasi

Lua WASI build.
C
5
star
28

git-by-example

Step-by-step guide to Git operations
4
star
29

runno

Runno WASI runtime.
TypeScript
4
star
30

nalgeon.github.io

Everything about SQLite, Python, open data and awesome software
JavaScript
3
star
31

asylum

Β«ΠŸΡΠΈΡ…Π±ΠΎΠ»ΡŒΠ½ΠΈΡ†Π°Β» ΠšΡƒΠΏΠ΅Ρ€Π° 20 Π»Π΅Ρ‚ спустя
CSS
2
star
32

sqlite-ext

All "miscellaneous" SQLite extensions from sqlite.org
Makefile
2
star
33

nalgeon

2
star
34

sql-window-functions

SQL Window Functions Explained
2
star
35

curl-by-example

Step-by-step guide to curl operations
2
star
36

inline-css

A native CSS framework for rapid UI development.
HTML
1
star
37

wee

Toy WSGI-compatible web framework
Python
1
star
38

rosenc

HTML
1
star
39

ruby-wasi

Ruby WASI build.
JavaScript
1
star
40

actionist

GitHub Actions Playground
C
1
star
41

grep-by-example

Step-by-step guide to grep operations
1
star