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.

Links

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.

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. See the Performance section below for benchmark results comparing the C runtime, the pure-Python runtime, and native Python.

Performance

The make perf target benchmarks the BareScript runtime with a suite of compute-intensive tests — Mandelbrot set computation, Markdown parsing and rendering, QR code generation, Schema Markdown parsing and validation, and URL encoding and decoding — and compares each test with an equivalent native Python program (using the schema-markdown package).

The following results are from make perf PERF_MERGE= (CPython 3.14, Apple M-series). "BareScript (PyC)" is the C runtime; "BareScript (Py)" is the pure-Python runtime. Times are the best per-run timing in milliseconds per 100 runs. Multiples are relative to the native Python time. Tests without a native Python equivalent are omitted.

Test Language Time (ms) Multiple
mandelbrot Python 4630.9
BareScript (PyC) 10900.0 2.4x
BareScript (Py) 341300.0 73.7x
schemaValidate Python 20.7
BareScript (PyC) 105.6 5.1x
BareScript (Py) 1433.2 69.2x
urlEncode Python 1.1
BareScript (PyC) 5.7 5.4x
BareScript (Py) 39.6 37.5x
schemaParse Python 17.2
BareScript (PyC) 123.6 7.2x
BareScript (Py) 904.8 52.7x
urlDecode Python 1.2
BareScript (PyC) 13.2 11.2x
BareScript (Py) 68.8 58.3x

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.6

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.6
File Size Uploaded
bare_script-5.1.6.tar.gz 218.2 kB Details

Built distribution (wheel)

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

Total release size: 434.8 kB

Release files / bare_script-5.1.6.tar.gz

Download URL bare_script-5.1.6.tar.gz
Size 218.2 kB
Tags Source
SHA-256 checksum
How to use checksums
532096487a57fd64655ccb4130bf3618118322a728900d554923e27257d24c8b
BLAKE2b-256 checksum
How to use checksums
0ea0ae9ff66c9ce88a5530895a3e9f60cf22e6379c17a4655d33acf53f6a98ef
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.6-cp314-cp314-macosx_26_0_arm64.whl

Download URL bare_script-5.1.6-cp314-cp314-macosx_26_0_arm64.whl
Size 216.5 kB
Tags CPython 3.14 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
8f7f646c458c134ce4f08a9d97c66ffa8bcb334111b636b479b51165d58bb689
BLAKE2b-256 checksum
How to use checksums
db3d4efb2d108d46ccab05eb66bd05367a559e7fb82f5912ca7252242e84bd99
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

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

This release

5.1.6 This release

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