Complexity Explorer Santa Few Institute

Agent-Based Models with Python: An Introduction to Mesa

Lead instructor:

Your progress is not being saved! Enroll now or log in to track your progress or submit homework.
About the Tutorial:

This tutorial introduces Agent-Based Modeling with the python-based library Mesa, through the seminal Sugarscape with Traders model from Growing Artificial Societies by Joshua M. Epstein and Robert L. Axtell (1996). This model represents an advanced beginner model and users should have some introductory experience to Python or other object oriented language syntax. This tutorial consists of 21 lessons with two introductory lessons, 18 coding lessons, and a brief conclusion. The tutorial is demonstrated through Google Colab, which is free to anyone with a Google account, and no installations or other environment setup is needed. Each lesson's code is available through Complexity Explorer's GitHub page and the entire code is available through Mesa's examples repository.   

About the Instructor(s):

Thomas Pike has been on the Mesa development since 2018, when he made his first contribution while attending the Santa Fe Institute's Complex Systems Summer School. He earned his Ph.D. in Computational Social Science from George Mason University and is a strong advocate for technical literacy and open source software as a global public good. His main areas of research are on the use of agent-based models to support policy development and using complex systems to understand the dynamics of resilient and robust democracies. 

Jackie Kazil is one of the creators of Mesa and a former White House Presidential Innovation Fellow. She started the project in 2015 after noticing a gap in the Python ecosystem for a library that does agent-based modeling. She is a leader in the Python community and an advocate for open source and accessibility to technology. She worked on her Ph.D. at George Mason University in Computational Social Science with a research area focused in the development of Mesa and agent-based modeling tooling in Python. 

How to use Complexity Explorer
Enrolled students:



Participants should have a basic understanding of Python or object-oriented programming.

Like this tutorial?


  1. Session 1: Introduction
  2. Session 2: Sugarscape with Traders Overview
  3. Session 3: Start Google Colab & Initiate Classes
  4. Session 4: Upload the Landscape
  5. Session 5: Agentize the Landscape Part I
  6. Session 6: Agentize the Landscape Part II
  7. Session 7: Initialize Traders
  8. Session 8: Sugar & Spice Step Functions
  9. Session 9: Traders Move Part I (Initiate Move)
  10. Session 10: Traders Move Part II (Identify Neighbors)
  11. Session 11: Traders Move Part III (Maximize Welfare)
  12. Session 12: Traders Move Part IV (Move to Best Closest Option)
  13. Session 13: Traders Eat
  14. Session 14: Traders Trade Part I (Get Neighbors)
  15. Session 15: Traders Trade Part II (MRS & Price)
  16. Session 16: Traders Trade Part III (Trade Sugar & Spice)
  17. Session 17: Traders Trade Part IV (Complete Trade)
  18. Session 18: Data Collector (Model Level)
  19. Session 19: Data Collector (Agent Level)
  20. Session 20: Batch Run
  21. Session 21: Conclusion