Connection of database with python

Hi,

Is there a way to connect the python model with a database? Do I need node.js for that ?
Also how to access and store values inside the database?
Is there a UI to see all databases stored?

Hello,

No, you don’t need node.js. There are python database drivers. If you place the python library in your model directory you can import it from there. The question is where your database resides? A database most often requires storage, operations and maintenance support, and we, here at Forio, are not a cloud database provider. However, there are actually a number of options. Can we take a step back and can I ask you what drives this need? How many tables do you think you’ll require, and how many total records? Is this relational data that you have, or just data you’re thinking about? Do you need SQL query capability?

If you provide a little background on what you’re looking for and why I can try to help.

Best,

David

Hi -

I wanted to follow up on this for the original poster and also anyone else reading this.

Epicenter has a built in database for storing and reading simulation results. When a user does a simulation run, all their inputs are automatically stored in the database, allowing the run to be replayed at any time. Calculated results of the simulation can be recorded. This is optional. (If a model has thousands of variables, usually only a small subset need to be permanently saved). Once the results are saved, Epicenter is able to show graphs/tables that quickly compare those results across many results (without needing to recalculate the models). The specifics about this can be found in our documentation in the “Writing Your Model” section and also “Model Context”.
https://forio.com/epicenter/docs/public/model_code/context/#ctx-save

In addition, simulation developers may want to bring in outside data. The most common way of doing this is to have the data in the form of CSV or other data files in the model directory. Your Python model (or Vensim model) can load that data when it runs. For more complex data, we’ve seen customers use SQLite files. Python has native bindings for SQLite, so it’s a great way to bring in a dump of structured outside data.

We rarely see customers access live databases outside the Forio system. This is generally because most such databases store transactional data while simulations generally need some level of aggregation or post processing. There’s also a reliability issue when you depend on availability of an external system. But if you develop a model in Python, as David points out in the note above, there’s lots of options in what you can connect too and this is definitely feasible.