Skip to main content

Folder structure

This guide deals with structuring your application folder: first by explaining the minimum structure as required by the platform and then by explaining a recommended structure with which the VIKTOR team had good experiences.

Minimum required structure

The minimum structure for a VIKTOR application is the following:

my-folder
├── app.py
├── requirements.txt
└── viktor.config.toml

From top to bottom:

  • app.py: (guide) Holds all the app logic and is the entry point of the application.
  • requirements.txt: (guide) Lists the Python dependencies of your project.
  • viktor.config.toml: (guide) Configuration settings of the application.

Large apps

The app.py file can quickly become cluttered with a lot of code if your app grows in size. For larger apps, we recommend to separate the code in sub-folders. This can be done by replacing the app.py file with a file called __init__.py within a folder named app. Like for app.py, it is possible to write the complete logic of your application in the __init__.py file now, but for the sake of readability we recommend to further separate the code in a sub-folder per entity type. Furthermore, it might be desirable to also split the Controller and Parametrization classes into separate files as such:

my-folder
├── app
│ ├── blue_type
│ │ ├── __init__.py
│ │ ├── controller.py
│ │ └── parametrization.py
│ ├── green_type
│ │ ├── __init__.py
│ │ ├── controller.py
│ │ └── parametrization.py
│ └── __init__.py <- this is the new entry point of your app, replacing app.py
├── requirements.txt
└── viktor.config.toml
note

The __init__.py files in the entity type sub-folders are required to make Python treat directories containing the file as packages and can be left empty.