Python or JavaScript scripting for NetLogo?

As of April 2018, there is a new kid on the block, PyNetLogo, and it is even available in PyPi for simple installation via pip.

Paper @ JASSS: PyNetLogo: Linking NetLogo with Python (March 2018)

Code @ Github

Documentation


There have been a bunch of NetLogo-clone type projects over the years, but they tend to founder and die once the creators realize how massively much work is involved in creating and sustaining something like NetLogo over a period of years and even decades. (Work on NetLogo and its predecessors in the StarLogo line stretches back to the late 1980s.)

2015 update: Mesa looks like a promising entrant in the ABM-for-Python space.

For those who like NetLogo's feature set and agent semantics but dislike the language, I think the most promising direction is the NetLogo Web project, by the developers of NetLogo (including myself, though as of 2015, I'm no longer heavily involved). In addition to being backwards compatible with the old NetLogo language, NLW also allows building models in JavaScript or any compile-to-JavaScript language.

NLW hasn't achieved full feature parity with regular NetLogo yet, but it's well on its way. So depending on your needs, it might just be a promising direction rather than a solution you can use today.

You might also take a look at AgentScript — also JavaScript based, with a CoffeeScript bias (2015 update: I think they are switching to ES6?).

2020 update: A recent JavaScript and Python-based entrant (from StackOverflow founder Joel Spolsky!) is HASH: https://hash.ai


NetLogo as a language does have some flaws. The lack of a case statement is certainly a minor one; the lack of modularity above the function level is a bigger one for very complex simulations.

But things that should be simple to code usually are simple to code, albeit in a way that you might not be used to. It's all a matter of mindset: the Logo language has its roots in the Lisp family, and the best way to approach a problem in it is almost always from a functional programming point of view. If you try to maintain an imperative (or even "pythonic") mindset, you'll likely have to "contort your brain" constantly.

I would suggest posting questions here when you find yourself struggling with apparently simple things. There is a very good chance that someone will be willing to show you the "NetLogo way" of doing it.

That being said, there are two main ways for NetLogo to interface with other JVM languages, including Jython:

  • The Extensions API allows you to provide new primitives usable inside NetLogo. You could conceivably build the bulk of your model inside Jython, expose your code through extension primitives, and keep the stuff that you have to code inside NetLogo to a minimum.

  • The Controlling API allows you to control NetLogo from an external program. In this scenario, you would code your model in Jython and use NetLogo as an external simulation engine/library.

But if your goal is just to build simulations, I'm not sure that you would gain a lot by taking these roundabout ways. You might as well switch to a different platform like MASON or Repast or just, you know... learn to love NetLogo.