Building the Backend

While the front-end of your Anvil app controls how the UI looks and behaves, the back-end takes care of your app’s functionality and infrastructure.

Front-end code runs in the user’s browser, or client, which means the user has complete access to this code and can do whatever they want with it. In the back-end, we can write code that can’t run in a browser and code that we don’t want our end users to see or touch.

Anvil provides a server-side Python environment for your apps which takes care of running your app’s infrastructure in a secure environment, not in a browser controlled by your end users. In this server environment, you can run long processes that persist beyond a user’s session, send emails, and much more. Back-end code in Anvil is not accessible by the client, so it can house sensitive code and connect securely to your Data Tables. It’s also a Python 3.10 environment, which means you can install your favourite Python packages to run complex processes.

Server Modules

Anvil’s Server Modules are a full server-side Python environment, with the ability to import any packages you like.

Installing Python Packages

Your Server Module code runs in a Python 3.10 environment on the Anvil server. Here, you can install any third-party Python packages you need into your app’s environment.

Background Tasks

Background Tasks allow you to fire off a function to run in the background, leaving your main program to continue executing while the function is running.

Scheduled Tasks

Sometimes you want to run server functions at particular times, regardless of user activity on your app. For users on paid plans, Scheduled Tasks let you do just that.

Sending and Receiving Email

Your apps can send and receive email using the built-in Email Service.

Sessions and Cookies

Anvil uses session tokens to allow you to store data in Server Modules for the duration of a user’s session.

Anvil also lets you store small amounts of data in between sessions through cookies, which are stored in the user’s browser.

Call Context

Call context, available through the anvil.server.context object, provides information about where your code is running and where it was called from.

Offline Apps

Anvil apps can function offline. An app’s client-side code will continue to work if the device loses its internet connection, though some offline strategies are required to handle code that communicates with the server.


Do you still have questions?

Our Community Forum is full of helpful information and Anvil experts.