{"id":6240,"library":"simpy","title":"SimPy","description":"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.","status":"active","version":"4.1.1","language":"en","source_language":"en","source_url":"https://github.com/simpy/simpy","tags":["simulation","discrete-event","process-based","modelling","generators"],"install":[{"cmd":"pip install simpy","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The core simulation environment.","symbol":"Environment","correct":"import simpy\nenv = simpy.Environment()"},{"note":"Common shared resource for modeling limited capacity.","symbol":"Resource","correct":"from simpy import Environment, Resource"},{"note":"Resource for modeling discrete quantities of a substance.","symbol":"Container","correct":"from simpy import Environment, Container"},{"note":"Resource for storing and retrieving arbitrary Python objects.","symbol":"Store","correct":"from simpy import Environment, Store"}],"quickstart":{"code":"import simpy\n\ndef car(env):\n    while True:\n        print(f'Start parking at {env.now}')\n        parking_duration = 5\n        yield env.timeout(parking_duration)\n\n        print(f'Start driving at {env.now}')\n        trip_duration = 2\n        yield env.timeout(trip_duration)\n\n\nenv = simpy.Environment()\nenv.process(car(env))\nenv.run(until=15)","lang":"python","description":"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."},"warnings":[{"fix":"Ensure Python >= 3.8. Replace `simpy.BaseEnvironment` with `simpy.Environment`. Update imports and code accordingly.","message":"SimPy 4.0 dropped support for Python 2.7 and requires Python 3.6+ (Python 3.8+ for 4.1.x). `BaseEnvironment` was removed; users should inherit from `Environment` instead.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Replace `env.exit(value)` or `raise simpy.exceptions.StopProcess(value)` with `return value` within generator functions.","message":"In SimPy 4.0, the `Environment.exit()` method and `StopProcess` exception were eliminated. Process generators that need to return a value or exit early must now use the standard Python `return` keyword.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Rewrite process functions to be generator functions that yield event objects from the environment (e.g., `env.timeout()`, `resource.request()`). Consult the SimPy 2 to 3 porting guide if migrating older code.","message":"SimPy 3.x introduced a major API overhaul from SimPy 2.x. Processes no longer needed to subclass `Process` and now yield event objects directly (e.g., `yield env.timeout(1)` instead of `yield hold, self, 1`).","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure your problem fits a discrete-event, process-based model with interacting components. For fixed-step or continuous simulations without complex interactions, other tools might be more suitable.","message":"SimPy is a discrete-event simulation library. It is not designed for continuous simulations or fixed-step simulations where processes do not interact or use shared resources. Using it for such scenarios can be overkill or lead to unidiomatic code.","severity":"gotcha","affected_versions":"All"},{"fix":"Familiarize yourself with Python generators and coroutines. Remember that code within a process generator only executes up to a `yield` statement, then resumes when the yielded event is processed.","message":"SimPy processes are Python generator functions. Understanding `yield` is crucial; it suspends a process until an event occurs, returning control to the simulation. Misunderstanding generator execution flow can lead to logical errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}