A transport simulator built for transport research
Project description
pytms
A lightweight, open-source transport simulator for research.
pytms lets you define a transport network and run multi-service simulations in Python. It is built around a Go simulation engine and a NetworkX-based API for building networks.
Features
- Mode-independent — model rail, bus, or any dedicated-corridor system with fixed stopping patterns
- Braking-distance separation between services
- Edge speed limits with automatic lookahead braking
- Staggered service departures
- Extensible kinematics (constant acceleration/deceleration today, more planned)
- NetworkX-compatible — use any nx tool for analysis, path-finding, or visualisation
Installation
pip install pytms
Requires Python 3.12 or later.
Quick start
import pytms
# Build a network
net = pytms.Network()
net.add_node("A")
net.add_node("B")
net.add_edge("A", "B", length=1000.0) # length in metres
net.add_edge("B", "A", length=1000.0, speed_limit=30)
# Define a vehicle
vehicle = pytms.Vehicle(
name="Train",
length=50.0, # metres
v_max=50.0, # m/s
a_acc=0.5, # m/s²
a_dcc=0.7, # m/s²
)
# Define a service
service = pytms.Service(
service_id="S1",
vehicle=vehicle,
initial_position="A",
route=[
pytms.RouteStop("B", t_dwell=30.0),
pytms.RouteStop("A", t_dwell=30.0),
],
)
net.add_service(service)
# Run the simulation
result = net.run(run_time=600.0, time_step=1.0)
print(result)
# SimulationResult(simulation_id='...', steps=601)
# Access the raw output
for row in result.output:
print(row["timestamp"], row["service_logs"])
Network
pytms.Network extends networkx.DiGraph. All standard NetworkX operations work including visualisations.
Edge attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
length |
float |
Yes | Edge length in metres |
speed_limit |
float |
No | Maximum speed on this edge (m/s) |
Services
A Service defines a vehicle travelling a repeated route between stops.
service = pytms.Service(
service_id="S1", # unique identifier
vehicle=vehicle,
initial_position="A", # starting node
route=[ # list of stops in order
pytms.RouteStop("B", t_dwell=30.0),
pytms.RouteStop("A", t_dwell=30.0),
],
departure_delay=60.0, # seconds before departing (optional, default 0)
)
Multiple services can be added to a network and will interact through braking-distance separation:
net.add_service(service_a)
net.add_service(service_b)
result = net.run(run_time=600.0, time_step=1.0)
Results
net.run() returns a SimulationResult:
result.meta # simulation metadata dict
result.output # list of timestep dicts, one per time step
result.to_dict() # full raw output as a Python dict
Each entry in result.output has the shape:
{
"timestamp": 42.0,
"service_logs": [
{
"service_id": "S1",
"state": "accelerating", # stationary | accelerating | cruising | decelerating | dwelling
"velocity": 12.3, # m/s
"current_position": {"edge": "A->B", "distance_along_edge": 450.0},
"next_stop": "B",
"remaining_dwell": 0.0,
}
]
}
Architecture
pytms is a thin Python wrapper around tms-engine, a simulation engine written in Go. The Python layer handles network construction and result parsing; the engine handles all simulation logic. Communication is via JSON over a subprocess call.
Licence
MIT
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 pytms-0.1.1.tar.gz.
File metadata
- Download URL: pytms-0.1.1.tar.gz
- Upload date:
- Size: 8.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.2","id":"zara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
063a5ff2e8a725fec2ead066fa6913ea9e2c11146998a5ae9b360f0aef182eea
|
|
| MD5 |
956768eaf95de915e8d05103eff1ee4c
|
|
| BLAKE2b-256 |
1b921a876c999b3bb93f4003aeeb8abb974647591ae31e715b3bf4e923c87785
|
File details
Details for the file pytms-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pytms-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.2","id":"zara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8db542d490a5c7aeda8c37473c29f99a9e6f009fc47d976ad12a88e8a199c2ba
|
|
| MD5 |
e87a6d24aabd3c20edc2ead23d3dc684
|
|
| BLAKE2b-256 |
de1837d5bef893d3960ad0b49fdc874ff62b0397dad0bb6e014f0b3e303e6a12
|