{"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":"python","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,"search_vec":"'4.1.1':66 'activ':34,70 'agent':40 'also':42 'base':7,13,82 'cadenc':72 'capac':52 'checkout':57 'compon':35 'congest':53 'counter':58 'current':63 'custom':37 'defin':21 'discret':9,78 'discrete-ev':8,77 'event':10,79 'exampl':29 'follow':68 'framework':12 'function':25 'generat':24,84 'like':36,55 'limit':51 'model':33,50,83 'point':54 'process':6,17,81 'process-bas':5,80 'provid':43 'python':16,23 'regular':74 'releas':71 'resourc':48 'server':56 'share':47 'simpi':1,2,19,41 'simul':11,76 'standard':15 'tunnel':60 'type':45 'updat':75 'use':31 'various':44 'vehicl':38 'version':65","created_at":"2026-04-14T18:48:02.697882+00:00","updated_at":"2026-04-16T21:46:06.353367+00:00","problems":[{"fix":"Call the process function with its arguments when passing it to `env.process()` to create a generator object.  \n```python\nimport simpy\n\ndef my_process(env):\n    yield env.timeout(1)\n\nenv = simpy.Environment()\nenv.process(my_process(env)) # Correct: call the function\nenv.run()\n```","cause":"This error occurs when `env.process()` is called with a function object itself, instead of a generator object obtained by calling the function with its arguments.","error":"TypeError: 'function' object is not an iterator"},{"fix":"Use `simpy.Resource` for managing discrete resource units (like servers or machines) with `request()` and `release()` methods. For `simpy.Container`, use `get()` and `put()` to manage quantities.  \n```python\nimport simpy\n\nenv = simpy.Environment()\nresource = simpy.Resource(env, capacity=1) # Use simpy.Resource for request/release\n\ndef process(env, res):\n    with res.request() as req:\n        yield req\n        print(f'{env.now}: Resource obtained!')\n\nenv.process(process(env, resource))\nenv.run()\n```","cause":"This error occurs when a SimPy `Container` is mistakenly treated as a `Resource`, attempting to call the `request()` method which does not exist on a `Container` object.","error":"AttributeError: 'Container' object has no attribute 'request'"},{"fix":"Rewrite the process function using a standard `def` and `yield` for SimPy events, instead of `async def` and `await`.  \n```python\nimport simpy\n\ndef my_process(env): # Standard generator function\n    print(f'{env.now}: Process started')\n    yield env.timeout(1) # Use yield for SimPy events\n    print(f'{env.now}: Process finished')\n\nenv = simpy.Environment()\nenv.process(my_process(env))\nenv.run()\n```","cause":"This error occurs when an `async def` (coroutine) function is passed to `env.process()`. SimPy expects a traditional generator function (defined with `def` and containing `yield`), not Python's `async/await` syntax.","error":"TypeError: 'coroutine' object is not an iterator"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.1.2","cli_name":"","cli_version":null,"type":"library","homepage":"https://simpy.readthedocs.io","github":null,"docs":"https://simpy.readthedocs.io","changelog":null,"pypi":"https://pypi.org/project/simpy/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","testing","workflow"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}