Python-to-NetLogo transpiler and integration toolkit
Project description
xnLogo
A Python-to-NetLogo transpiler and integration toolkit for agent-based modeling.
Overview
xnLogo enables researchers and developers to write agent-based simulations in Python and compile them to NetLogo. The system provides transpilation (Python to NetLogo code generation) and runtime integration (controlling NetLogo models from Python).
Write models using Python's syntax and tooling, then execute them in NetLogo's simulation environment.
Installation
pip install xnlogo
Requirements:
- Python 3.10 or later
- NetLogo 7.0 or later (for running compiled models)
- Java 17 or later (for runtime integration)
Quick Start
Create counter.py:
from xnlogo import agent
@agent
class Counter:
count: int = 0
def increment(self):
self.count = self.count + 1
def reset(self):
self.count = 0
Compile to NetLogo:
xnlogo build counter.py
This generates counter.nlogox which can be opened in NetLogo 7.
Features
- Agent-based modeling - Define agents with state and behaviors using Python classes
- Semantic validation - Detect unsupported constructs before compilation
- NetLogo 7 support - Generate
.nlogoxfiles (legacy.nlogoalso supported) - Runtime integration - Run simulations and collect telemetry from Python
- Type annotations - Use Python type hints for agent state fields
- CLI tools - Complete command-line interface for validation, compilation, and execution
Command-Line Interface
| Command | Purpose |
|---|---|
xnlogo check <path> |
Validate Python code without compiling |
xnlogo build <path> |
Compile to NetLogo format |
xnlogo run <path> |
Execute simulation in NetLogo |
xnlogo export <path> |
Export telemetry data to CSV/JSON |
Example: Flocking Model
from xnlogo import agent
@agent
class Boid:
speed: float = 1.0
heading: float = 0.0
def setup(self):
self.speed = 0.5 + self.random_float(0.5)
self.heading = self.random_float(360)
def flock(self):
neighbors = self.nearby_agents(self, Boid, radius=3)
if neighbors:
avg_heading = sum(n.heading for n in neighbors) / len(neighbors)
turn = (avg_heading - self.heading) * 0.05
self.heading = self.heading + turn
self.forward(self.speed)
Compile and run:
xnlogo build flocking.py
xnlogo run flocking.py --ticks 100
Runtime Integration
Execute models and collect data from Python:
from pathlib import Path
from xnlogo.runtime.session import NetLogoSession, SessionConfig
config = SessionConfig(netlogo_home=Path("/Applications/NetLogo 7.0.0"))
with NetLogoSession(config) as session:
session.load_model(Path("flocking.nlogox"))
session.command("setup")
session.repeat("go", 100)
population = session.report("count turtles")
avg_speed = session.report("mean [speed] of turtles")
Documentation
- User Guide - Detailed usage and examples
- Architecture - System design and internals
- Translation Rules - Python to NetLogo conversion reference
- Python-NetLogo Compatibility - Feature compatibility matrix
Project Status
xnLogo is under active development. Core features are stable:
- Agent parsing and compilation
- Python-to-NetLogo statement translation
- Semantic validation
- Runtime integration
- NetLogo 7
.nlogoxoutput
Advanced NetLogo features (breeds, links, extensions) are in progress.
License
MIT License
Acknowledgments
Built on NetLogo by Uri Wilensky and the CCL at Northwestern University.
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 xnlogo-0.1.0.tar.gz.
File metadata
- Download URL: xnlogo-0.1.0.tar.gz
- Upload date:
- Size: 29.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7864cf767931e49eba7e4f195c4e3399a2b5a08c13395cd8821fbabfc3d6371
|
|
| MD5 |
0f7c7da7b96f34daafbc32834c4a2abc
|
|
| BLAKE2b-256 |
a0a38aa0c310c812952ab501529932ce19eed358e967991c5cdde57cb59484cf
|
File details
Details for the file xnlogo-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xnlogo-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
916fc1d9b35d4f6a17157367ba5c61bcc7831d117ff9351a32379cbdf570a776
|
|
| MD5 |
6b73216e5a799db7f1bc4f1e0132f1ca
|
|
| BLAKE2b-256 |
007e24c4b237694ed6177dd96f49c8a6cf23c943fd655c8a900a5826fdee8541
|