There are two types of Python code in Anvil: Server Modules (which run on the Anvil server) and Form code (which runs in the user’s web browser).
Server Modules run on Anvil’s servers (you don’t have to set up your own servers – just write the code and call it!). The users of your app can’t see or change the code in your Server Modules.
You can choose to run your app’s Server Modules with Python 2.7 or 3.7, if you’re using a paid account:
Free Plan users must use the Restricted Python 2 environment, which has fewer libraries available to import. (Free Plan users can still use the Uplink, though!)
The user of an app can see the source code for your Forms (via “View Source” in their web browser). The can also change how forms behave in your browser – so don’t rely on code in your Forms to enforce security! See our security documentation for more information.
Sometimes you want to write library code that can be used on the server and in the browser. To do this, create a Module. You can import Module code from the client or the server.
Module code is loaded in the same environment as whatever is importing it. If you import a Module from a Form, it will be loaded in Python 2; if you import from server code, it will be loaded in whichever Python version you have chosen.
The user of an app can see source code for your Modules. They can also manipulate how Module code behaves in the browser. (Of course, this doesn’t change how Modules behave when they’re imported by Server Modules and running on Anvil’s servers.)
If use the Uplink to connect your app to code running outside Anvil, that code runs in whatever version of Python you are using with the Uplink. The user of an app cannot see or modify Uplink code.
For more details, you can read our reference documentation: