Write markdown files mixing Python code with natural language prompts that generate and execute additional code in a shared runtime
Project description
psyborg
An agentless vibe coding framework for seamlessly mixing code and LLM instructions in executable markdown files. psyborg enables you to write polyglot programs that support both traditional programming languages and natural language instructions, all executed in a shared runtime environment.
Overview
psyborg lets you write markdown files that mix Python code with natural language instructions. The code blocks execute normally, while text between them becomes prompts for an LLM to generate and execute additional code - all in the same runtime environment with shared variables.
Features
- Seamless Integration: Mix Python code and natural language instructions in markdown files
- Shared Runtime: All code blocks and LLM-generated code share the same execution context
- State Preservation: Variables and their values persist across code blocks and LLM instructions
- Simple Syntax: Use standard markdown code blocks and plain text instructions
- Flexible LLM Backend: Supports OpenAI-compatible APIs (including local models)
- Easy Installation: Available as a pip-installable package with CLI support
- Code Export: Generate standalone Python scripts from your psyborg executions for reuse
- Smart Caching: Automatic caching of code execution results and LLM responses for faster iterative development
Installation
From PyPI (Recommended)
pip install psyborg
From Source (Development)
git clone https://github.com/m4xw311/psyborg.git
cd psyborg
pip install -e .
For development with additional tools:
pip install -e ".[dev]"
Configuration
Create a .env file in your project directory with your OpenAI API configuration:
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_BASE_URL=https://api.openai.com/v1 # Optional: for custom endpoints
OPENAI_MODEL=gpt-4 # Optional: defaults to gpt-4
Alternatively, you can set these as environment variables:
export OPENAI_API_KEY="your_openai_api_key_here"
export OPENAI_BASE_URL="https://api.openai.com/v1" # Optional
export OPENAI_MODEL="gpt-4" # Optional
Quick Start
- Create a markdown file (e.g.,
hello.md):
# My First psyborg Script
```python
name = "World"
print(f"Hello, {name}!")
Now create a greeting function that takes a name parameter and returns a personalized greeting.
print(greeting("psyborg"))
2. **Run it with psyborg**:
```bash
psyborg hello.md
The output will show:
- "Hello, World!" from the first code block
- The LLM will generate a
greeting()function based on your instruction - "Hello, psyborg!" from calling the generated function
How It Works
psyborg processes your markdown file sequentially:
- Code blocks (```python) are executed directly in the Python interpreter
- Text sections between code blocks are sent to the LLM as prompts to generate new code
- Generated code is executed in the same runtime environment
- Variables and functions persist across all code blocks and LLM generations
- Results are displayed in real-time as execution progresses
Command Line Options
psyborg [options] <markdown_file>
Options:
-h, --help Show help message
-v, --verbose Enable verbose output for debugging
--version Show version information
--clear-cache Clear execution cache before running
--export FILE Export executed code to a Python file
--dry-run Parse and validate without executing
Examples
# Basic execution
psyborg script.md
# Export the executed code to a Python file
psyborg script.md --export output.py
# Clear cache and run with verbose output
psyborg script.md --clear-cache --verbose
# Validate syntax without executing
psyborg script.md --dry-run
Advanced Usage
Working with Variables
Variables defined in code blocks are available to subsequent LLM instructions:
```python
data = [1, 2, 3, 4, 5]
Create a function to calculate the average of the data list.
print(f"Average: {calculate_average(data)}")
### Multiple Instructions
You can have multiple instruction sections that build upon each other:
```markdown
```python
import pandas as pd
df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})
Add a new column 'z' that is the sum of columns 'x' and 'y'.
Now create a visualization of all three columns using matplotlib.
print("Final DataFrame:")
print(df)
### Custom LLM Endpoints
psyborg supports any OpenAI-compatible API endpoint:
```bash
# For local models (e.g., Ollama, LocalAI)
export OPENAI_BASE_URL="http://localhost:11434/v1"
export OPENAI_API_KEY="not-needed"
export OPENAI_MODEL="llama2"
# For other providers
export OPENAI_BASE_URL="https://your-provider.com/v1"
export OPENAI_API_KEY="your-key"
export OPENAI_MODEL="your-model"
Caching
psyborg automatically caches:
- Code execution results
- LLM responses for identical prompts
- Variable states between runs
Cache is stored in .psyborg_cache/ and persists across sessions. Use --clear-cache to reset.
Code Export
Generate standalone Python scripts from your psyborg executions:
psyborg script.md --export generated_script.py
The exported file includes:
- All original code blocks
- LLM-generated code with comments indicating their source
- Proper imports and structure for standalone execution
Best Practices
- Start Simple: Begin with basic Python code blocks and simple instructions
- Be Specific: Clear, specific instructions yield better LLM-generated code
- Iterative Development: Use psyborg's caching for fast iteration cycles
- Variable Context: Remember that the LLM can see and use all previously defined variables
- Export for Production: Use
--exportto create deployable Python scripts
Examples
Check the examples/ directory for sample psyborg scripts demonstrating various use cases:
- Data analysis and visualization
- Web scraping and API integration
- Machine learning workflows
- File processing and automation
- Mathematical computations
Troubleshooting
Common Issues
"OpenAI API key not found"
- Set
OPENAI_API_KEYin your environment or.envfile
"Module not found" errors
- Install required Python packages:
pip install package-name
Cache-related issues
- Clear cache with:
psyborg script.md --clear-cache
LLM generates incorrect code
- Be more specific in your instructions
- Provide examples of expected input/output
- Break complex tasks into smaller steps
Debug Mode
Use verbose mode to see detailed execution information:
psyborg script.md --verbose
This shows:
- Cache hit/miss information
- LLM prompts and responses
- Code execution details
- Variable state changes
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Development Setup
git clone https://github.com/m4xw311/psyborg.git
cd psyborg
pip install -e ".[dev]"
Running Tests
pytest
pytest --cov=psyborg # With coverage report
License
MIT License - see LICENSE file for details.
Changelog
See CHANGELOG.md for version history and release notes.
psyborg - Where code meets natural language in perfect harmony. 🤖✨
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 psyborg-0.4.0.tar.gz.
File metadata
- Download URL: psyborg-0.4.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fce4f6055c3bf4ce3181cc0384d32cf38a99cb993024784139789a910ae92b46
|
|
| MD5 |
1fc19eb08a341fad77517f2d147ade06
|
|
| BLAKE2b-256 |
13f0fe84c3ae0a97cfecf572583c1c9a087118f196821d7e7921e879f032a4ba
|
Provenance
The following attestation bundles were made for psyborg-0.4.0.tar.gz:
Publisher:
workflow.yml on m4xw311/psyborg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psyborg-0.4.0.tar.gz -
Subject digest:
fce4f6055c3bf4ce3181cc0384d32cf38a99cb993024784139789a910ae92b46 - Sigstore transparency entry: 462140007
- Sigstore integration time:
-
Permalink:
m4xw311/psyborg@0417a3e8fd9a3c7671e5e71655504d8a82a7a903 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/m4xw311
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@0417a3e8fd9a3c7671e5e71655504d8a82a7a903 -
Trigger Event:
push
-
Statement type:
File details
Details for the file psyborg-0.4.0-py3-none-any.whl.
File metadata
- Download URL: psyborg-0.4.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b28e41133387bdcf3c9d083a1c3770f9ff518700919d1ca2b9bb00064a1bc274
|
|
| MD5 |
a9857e8ea1eb2ea9d2a57364fd0b7746
|
|
| BLAKE2b-256 |
81c6becdecce2c7905bb06edd3ceea2bb16ee447e7431fb737a6eec87efe50f6
|
Provenance
The following attestation bundles were made for psyborg-0.4.0-py3-none-any.whl:
Publisher:
workflow.yml on m4xw311/psyborg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psyborg-0.4.0-py3-none-any.whl -
Subject digest:
b28e41133387bdcf3c9d083a1c3770f9ff518700919d1ca2b9bb00064a1bc274 - Sigstore transparency entry: 462140044
- Sigstore integration time:
-
Permalink:
m4xw311/psyborg@0417a3e8fd9a3c7671e5e71655504d8a82a7a903 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/m4xw311
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@0417a3e8fd9a3c7671e5e71655504d8a82a7a903 -
Trigger Event:
push
-
Statement type: