SimPy

4.1.1 · active · verified Tue Apr 14

SimPy is a process-based discrete-event simulation framework based on standard Python. Processes in SimPy are defined by Python generator functions and can, for example, be used to model active components like customers, vehicles or agents. SimPy also provides various types of shared resources to model limited capacity congestion points (like servers, checkout counters and tunnels). It is currently at version 4.1.1 and follows an active release cadence with regular updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a simple 'car' process that alternately parks and drives. It showcases environment creation, defining a process as a generator function, scheduling the process, and running the simulation for a specified duration. The `env.timeout()` event is used to simulate the passage of time.

import simpy

def car(env):
    while True:
        print(f'Start parking at {env.now}')
        parking_duration = 5
        yield env.timeout(parking_duration)

        print(f'Start driving at {env.now}')
        trip_duration = 2
        yield env.timeout(trip_duration)


env = simpy.Environment()
env.process(car(env))
env.run(until=15)

view raw JSON →