Skip to main content

bare-script

PyPI - Status PyPI GitHub PyPI - Python Version

BareScript is a simple, lightweight, and portable programming language. Its Pythonic syntax is influenced by JavaScript, C, and the Unix Shell. BareScript also has a library of built-in functions for common programming operations. BareScript can be embedded within applications or used as a stand-alone programming language using the command-line interface.

There are two implementations of BareScript: BareScript for Python (this package) and BareScript for JavaScript. Both implementations have 100% unit test coverage with identical unit test suites, so you can be confident that BareScript will execute the same regardless of the underlying runtime environment.

Installation

Install the bare-script package with pip — it includes the bare command-line interface:

pip install bare-script

Executing BareScript Scripts

To execute a BareScript script, parse the script using the barescript_parse_script function. Then execute the script using the execute_script function. For example:

from bare_script import barescript_parse_script, execute_script

# Parse the script
script = barescript_parse_script('''\
# Double a number
function double(n):
    return n * 2
endfunction

return N + ' times 2 is ' + double(N)
''')

# Execute the script
globals = {'N': 10}
print(execute_script(script, {'globals': globals}))

This outputs:

10 times 2 is 20

The BareScript Library

The BareScript Library documents the built-in functions available to every script and the include libraries loaded with the include statement. Built-in functions cover mathematical operations, object and array manipulation, regular expressions, HTTP fetch, and more. Angle-bracket includes (include <markdown.bare>) load libraries bundled with the runtime. Quoted includes (include 'util.bare') load a local file or URL.

The following example uses the built-in systemFetch, objectGet, and arrayLength functions:

from bare_script import barescript_parse_script, execute_script, fetch_http

# Parse the script
script = barescript_parse_script('''\
# Fetch the BareScript builtin library documentation JSON
docs = jsonParse(systemFetch('https://craigahobbs.github.io/bare-script-py/library/library-builtin.json'))

# Return the number of builtin functions
return 'The BareScript Library has ' + arrayLength(objectGet(docs, 'functions')) + ' builtin functions'
''')

# Execute the script
print(execute_script(script, {'fetchFn': fetch_http}))

This outputs:

The BareScript Library has 100 builtin functions

Include libraries are loaded before use:

from bare_script import barescript_parse_script, execute_script

# Parse the script
script = barescript_parse_script('''\
include <markdownParser.bare>
include <markdown.bare>

markdown = markdownParse('# Hello, Markdown!')
return markdownTitle(markdown)
''')

# Execute the script
print(execute_script(script))

This outputs:

Hello, Markdown!

Quoted includes and systemFetch calls with a non-URL path need a filesystem-aware fetch function. Pass fetch_read_only or fetch_read_write:

from bare_script import barescript_parse_script, execute_script, fetch_read_write

script = barescript_parse_script("include 'util.bare'")
execute_script(script, {'fetchFn': fetch_read_write})

Stub Functions

Include library functions are also callable directly from Python using the native stub functions exported by the include module — for example, data_aggregate, markdown_parse, qrcode_matrix, schema_parse, schema_validate, and url_encode. Each stub function executes its corresponding include library function using the BareScript runtime. For example:

from bare_script.include import markdown_parse, markdown_title

# Parse the Markdown text
markdown = markdown_parse('''\
# Hello, Markdown!

This is some text.
''')

# Print the Markdown title
print(markdown_title(markdown))

This outputs:

Hello, Markdown!

Evaluating BareScript Expressions

To evaluate a BareScript expression, parse the expression using the barescript_parse_expression function. Then evaluate the expression using the evaluate_expression function.

Expression evaluation includes the BareScript Expression Library, a set of built-in, spreadsheet-like functions.

For example:

from bare_script import barescript_parse_expression, evaluate_expression

# Parse the expression
expr = barescript_parse_expression('2 * max(a, b, c)')

# Evaluate the expression
variables = {'a': 1, 'b': 2, 'c': 3}
print(evaluate_expression(expr, None, variables))

This outputs:

6

The BareScript Command-Line Interface (CLI)

You can run BareScript from the command line using the BareScript CLI, "bare". BareScript script files use the ".bare" file extension.

bare script.bare                      # run a script
bare -c 'systemLog("Hello, World!")'  # execute inline code
bare -v N 10 script.bare              # set the global N to 10
bare -d script.bare                   # debug mode
bare -m app.bare                      # MarkdownUp text output
bare -l app.bare                      # MarkdownUp HTML output
bare -s script.bare                   # parse and lint only
bare -x script.bare                   # lint with execution

Note: In the BareScript CLI, include statements and the systemFetch function read non-URL paths from the local file system. systemFetch calls with a non-URL path and a request body write the body to the path.

MarkdownUp, a Markdown Viewer with BareScript

MarkdownUp is a Markdown Viewer that executes BareScript embedded within Markdown documents. The MarkdownUp runtime contains functions for dynamically rendering Markdown text, drawing SVG images, etc. For example:

# Markdown Application

This is a Markdown document with embedded BareScript:

```markdown-script
markdownPrint('Hello, Markdown!')
```

To run a MarkdownUp script (.bare) from this package, use bare -m (Markdown text) or bare -l (HTML). To view a MarkdownUp document (.md with markdown-script blocks), install the markdown-up viewer or open the file in the MarkdownUp web app.

The BareScript Creator

The BareScript Creator generates a ready-to-build BareScript project from a specification you write. Choose a project type (a MarkdownUp frontend application, to start), fill in its form, and download the project as a .tar.gz archive with a Makefile, a unit test suite, and the bare-script skill. In the project directory, make run has Claude Code, in your terminal, write the code and its tests from your specification, then serves the application in your browser. The creator keeps a history of your projects so you can refine a specification and create it again.

C Runtime

The package ships with an optional CPython C extension, runtime_c, that mirrors the pure-Python runtime for faster script execution. The compiled extension is used automatically when available; set the environment variable BARESCRIPT_RUNTIME_PY=1 to force the pure-Python runtime.

The extension supports CPython 3.10 and later on both the default (GIL) and free-threaded Python builds. Benchmarks comparing the C runtime, the pure-Python runtime, and native Python are on the BareScript (C) Performance.

Thread Safety

Both runtimes may be used from multiple threads, including on the free-threaded (no-GIL) Python builds. Script models and a globals dict may be shared across threads once populated - for example, execute a script that defines functions once, then call those functions concurrently. Each concurrently executing thread must pass its own options dict to execute_script, since the runtime records the running statementCount there. The parser, linter, and include library stubs initialize lazily and are safe to call from any thread. As in Python, unsynchronized concurrent mutation of a shared array or object from several threads has unspecified results but never crashes the runtime.

Performance

The C, JavaScript, and Python implementations share two benchmark suites: make perf (the include library, compared with native Python via schema-markdown) and make perfx (applications ported to six languages). Results live on the BareScript (C) Performance.

make perf
make perf PERF_MERGE=   # this implementation only

Using BareScript with an AI Assistant

This repository ships a SKILL.md file that teaches an AI coding assistant how to write idiomatic BareScript — language syntax, the built-in and include libraries, the MarkdownUp application pattern, and the unit-test conventions. It is plain Markdown and applies to either BareScript implementation. Assistants that discover SKILL.md at the repository root can use it without copying.

For Claude Code and other tools that follow the Agent Skills convention, install it as a project or user skill:

mkdir -p .claude/skills/bare-script
cp SKILL.md .claude/skills/bare-script/SKILL.md

Use ~/.claude/skills/bare-script/SKILL.md instead to make it available across all projects. For other assistants, include the file's contents in your system prompt or rules file.

Once installed, prompt the assistant with a task like:

claude "Build a MarkdownUp application that plays tic-tac-toe against the user, with a reset button and a running win/loss/draw tally rendered as a bar chart. Save it as ticTacToe.md"

To run the resulting MarkdownUp application locally, install the markdown-up viewer and point it at the Markdown file:

pip install markdown-up
markdown-up ticTacToe.md

The BareScript documentation is also published as plain Markdown, which can be fetched directly into an assistant's context alongside SKILL.md:

SKILL.md itself is published at https://craigahobbs.github.io/bare-script-py/SKILL.md, and https://craigahobbs.github.io/bare-script-py/llms.txt indexes all of the fetchable documentation.

Development

This package is developed using python-build. It was started using python-template as follows:

template-specialize python-template/template/ bare-script-py/ -k package bare-script -k name 'Craig A. Hobbs' -k email 'craigahobbs@gmail.com' -k github 'craigahobbs'

Metadata

Release files for bare-script 5.1.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bare-script 5.1.16
File Size Uploaded
bare_script-5.1.16.tar.gz 285.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bare-script 5.1.16
File Interpreter ABI Platform
bare_script-5.1.16-cp314-cp314-macosx_26_0_arm64.whl CPython 3.14 CPython 3.14 macOS 26.0+ ARM64 Details

Total release size: 570.7 kB

Release files / bare_script-5.1.16.tar.gz

Download URL bare_script-5.1.16.tar.gz
Size 285.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0a4dad70056d79a22e784f5e42927704dc17d7d54f4051e02cd3107022a2b98a
BLAKE2b-256 checksum
How to use checksums
9833583b8319cbb8eeef98304d087beb353131229a013c0553b255ac6e1911b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / bare_script-5.1.16-cp314-cp314-macosx_26_0_arm64.whl

Download URL bare_script-5.1.16-cp314-cp314-macosx_26_0_arm64.whl
Size 285.0 kB
Tags CPython 3.14 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
d26bd76e36ac4bde1187d29471164e2a61d579dc4a126165d230e085cfafb0ae
BLAKE2b-256 checksum
How to use checksums
8a1d5d394a5925345a79320a78a2968734a91b065a4bd58263109cda7f7a3c8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

5.1.16 This release

2 release files

5.1.14

2 release files

5.1.13

2 release files

5.1.12

2 release files

5.1.11

2 release files

5.1.9

2 release files

5.1.8

2 release files

5.1.7

2 release files

5.1.6

2 release files

5.1.5

2 release files

5.1.3

2 release files

5.1.2

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.5

2 release files

5.0.4

2 release files

5.0.3

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.2.12

2 release files

4.2.11

2 release files

4.2.10

2 release files

4.2.9

2 release files

4.2.8

2 release files

4.2.7

2 release files

4.2.6

2 release files

4.2.5

2 release files

4.2.4

2 release files

4.2.3

2 release files

4.2.2

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.11

2 release files

4.1.9

2 release files

4.1.8

2 release files

4.1.5

2 release files

4.1.4

2 release files

4.1.3

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.8.20

2 release files

3.8.19

2 release files

3.8.18

2 release files

3.8.16

2 release files

3.8.15

2 release files

3.8.14

2 release files

3.8.11

2 release files

3.8.10

2 release files

3.8.9

2 release files

3.8.8

2 release files

3.8.6

2 release files

3.8.5

2 release files

3.8.4

2 release files

3.8.3

2 release files

3.8.2

2 release files

3.8.1

2 release files

3.8.0

2 release files

3.7.6

2 release files

3.7.5

2 release files

3.7.4

2 release files

3.7.3

2 release files

3.7.2

2 release files

3.7.1

2 release files

3.6.0

2 release files

3.5.5

2 release files

3.5.4

2 release files

3.5.3

2 release files

3.5.2

2 release files

3.5.1

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.13

2 release files

3.0.12

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

0.9.10

2 release files

0.9.9

2 release files

0.9.8

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page