bare-script
Project description
bare-script
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
- The BareScript Language
- The BareScript Library
- The BareScript Include Library Tests
- API Documentation
- Source code
Executing BareScript Scripts
To execute a BareScript script, parse the script using the parse_script function. Then execute the script using the execute_script function. For example:
from bare_script import execute_script, parse_script
# Parse the script
script = 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 includes a set of built-in functions for mathematical operations, object manipulation, array manipulation, regular expressions, HTTP fetch and more. The following example demonstrates the use of the systemFetch, objectGet, and arrayLength functions.
import urllib.request
from bare_script import execute_script, fetch_http, parse_script
# Parse the script
script = parse_script('''\
# Fetch the BareScript library documentation JSON
docs = jsonParse(systemFetch('https://craigahobbs.github.io/bare-script-py/library/library.json'))
# Return the number of library functions
return 'The BareScript Library has ' + arrayLength(objectGet(docs, 'functions')) + ' functions'
''')
# Execute the script
print(execute_script(script, {'fetchFn': fetch_http}))
This outputs:
The BareScript Library has 209 functions
Evaluating BareScript Expressions
To evaluate a BareScript expression, parse the expression using the 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 evaluate_expression, parse_expression
# Parse the expression
expr = 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
Note: In the BareScript CLI, import 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!')
```
C Runtime
The package ships with an optional CPython C extension (runtime_c) that mirrors the pure-Python
runtime for faster script execution. When the compiled extension is available, it is used
automatically; otherwise the pure-Python runtime is used as a fallback. Set the environment
variable BARESCRIPT_RUNTIME_PY=1 to force the pure-Python runtime.
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.
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, you can prompt the assistant with tasks like:
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.
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'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bare_script-4.2.0.tar.gz.
File metadata
- Download URL: bare_script-4.2.0.tar.gz
- Upload date:
- Size: 129.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0775d41b9b92a813549ed2dfab34cc9bc58e828779cb88bfd385338543bda000
|
|
| MD5 |
01ceb4e966d7713547662c167495ac18
|
|
| BLAKE2b-256 |
5fdc2ad5f99167d23df5f5e375d53d95404207635a9336bd8578e4bed915d1b7
|
File details
Details for the file bare_script-4.2.0-cp314-cp314-macosx_26_0_arm64.whl.
File metadata
- Download URL: bare_script-4.2.0-cp314-cp314-macosx_26_0_arm64.whl
- Upload date:
- Size: 140.8 kB
- Tags: CPython 3.14, macOS 26.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4a87fd71362abea42a0524432778f929e3992b8bbf525647682d09f29d3c4ad
|
|
| MD5 |
63c4aa8ae3a88be00cb6a93dee108eaf
|
|
| BLAKE2b-256 |
040cb772ee78cab92ef6491b09af4e297dc898bd9bd0a7095b29db5e44b3a388
|