Scriptic
A minimalist, embeddable Python REPL with zero external dependencies.
Features
- Zero Dependencies: Uses only the Python standard library
- Lightweight: Single file implementation (~300 lines of code)
- Embeddable: Easily integrate into any Python application
- Extensible: Add custom commands with simple decorators
- Context Injection: Share your application objects with the REPL
- Multiline Support: Properly handles functions, classes, and blocks
- Signal Handling: Gracefully manages keyboard interrupts
- Command History: Up/down arrow navigation (when readline is available)
Installation
Simply copy scriptic.py into your project:
# From GitHub
curl -O https://raw.githubusercontent.com/LayerDynamics/scriptic/main/scriptic.py
# Or just copy the file directly to your project
Basic Usage
from scriptic import run_scriptic
# Start a basic REPL
run_scriptic(intro="Welcome to Scriptic!")
Embedding in Your Application
from scriptic import Scriptic
# Create your application objects
my_app = MyApplication()
# Set up the REPL context with your objects
context = {
"app": my_app,
"do_something": my_app.do_something,
}
# Create and configure the REPL
repl = Scriptic(
context=context,
prompt="myapp> ",
intro="MyApp Console - Type commands or %help"
)
# Add custom commands
def cmd_status(args):
"""Show the application status."""
print(f"App status: {my_app.get_status()}")
repl.register_command("status", cmd_status)
# Run the REPL
repl.run()
Built-in Commands
Scriptic comes with several built-in commands:
- %help - Display help for available commands
- %exit or %quit - Exit the REPL
- %vars - Show variables in the current context
- %reset - Reset the REPL context to initial state
- %run - Execute a Python file in the current context
- %load - Load a Python file into the buffer without executing it
Adding Custom Commands
Custom commands start with % and can take arguments:
def cmd_greet(args):
"""Greet a person by name.
Usage: %greet [name]
"""
name = args.strip() or "World"
print(f"Hello, {name}!")
repl.register_command("greet", cmd_greet)
In the REPL, you can call this with:
>>> %greet Alice
Hello, Alice!
Advanced Usage
Executing Python Files
Scriptic includes built-in support for running and loading Python files:
# In the REPL, execute a Python file in the current context
>>> %run script.py arg1 arg2
# The script.py file can access sys.argv as usual
# sys.argv[0] will be 'script.py'
# sys.argv[1] will be 'arg1'
# sys.argv[2] will be 'arg2'
# All definitions from the script become available in the REPL
>>> my_function_from_script()
# Load a file into the buffer without executing it
>>> %load another_script.py
# The file content will be displayed and added to the buffer
# You can edit it before executing
These commands make it easy to work with external Python files while maintaining the interactive nature of the REPL environment.
Customizing Signal Handling
Override the _handle_signal method for custom behavior:
class MyREPL(Scriptic):
def _handle_signal(self, sig, frame):
if sig == signal.SIGINT:
print("\nDo you want to exit? (y/n)")
if input().lower() == 'y':
self.running = False
else:
self.buffer = [] # Clear input buffer
Example Application
See example.py for a complete demonstration of embedding Scriptic in a simple application.
License
MIT License - Feel free to use and modify as needed!
Metadata
Release files for scriptic 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| scriptic-0.1.0.tar.gz | 32.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scriptic-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.9 kB
Release files / scriptic-0.1.0.tar.gz
| Download URL | scriptic-0.1.0.tar.gz |
|---|---|
| Size | 32.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0ba3667581c83e4ff48c11a5411ad64bac5b988279a080662dee48cd72b992d8
|
|
BLAKE2b-256 checksum How to use checksums |
878b1ad5eaac213b0f4bb43f46d3f69c1f0ec19315888ffcadd84d2bfbded3bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / scriptic-0.1.0-py3-none-any.whl
| Download URL | scriptic-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
248e1c37d3852af79235e2675a274e3c52c04b08c9105d92eac4a0d7ae9881dd
|
|
BLAKE2b-256 checksum How to use checksums |
c7e79ec0082230fe518e27d50081fb027f44ad1b87ce6aafc6723a7d60d2bacc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Security for scriptic 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.