Use any back-end﴾s﴿ you like
Anvil allows you to connect to Python code anywhere and make Python function calls directly from your app.
Follow this quickstart to call a Python function on your own machine from an Anvil app.
Log in to Anvil and click ‘create app’. Choose the Material Design theme.
Click on ‘Uplink’ in the Gear Menu :
You’ll see this dialog:
Click the green ‘Enable Uplink’ button. You’ll get a randomised id for your app.
You can also use a ‘client’ Uplink key that only gives the permissions available to client-side code. You can use this to connect to untrusted code with a restricted set of permissions so your data remains secure. We’ll stick with the server key for this quickstart.
On your own computer, install the Uplink library (ensure you have Python installed).
pip install anvil-uplink
Create a file called
hello.py with the following contents:
import anvil.server anvil.server.connect("<your Uplink key>") @anvil.server.callable def say_hello(name): print("Hello from your own machine, %s!" % name) anvil.server.wait_forever()
"<your Uplink key>" string with the Uplink key from your app.
Run the script. You should see output like this:
Connecting to wss://anvil.works/uplink Anvil websocket open Authenticated OK
Back in the Anvil Editor, close the Uplink dialog and click on the ‘Code’ tab to see the Python code for
You will see a few lines of pre-written code. Your Form is represented as a class called Form1. It currently has
only one method, the
At the end of the
__init__ method, write this line:
anvil.server.call('say_hello', 'Anvil Developer')
Now click the ‘Run’ button at the top of the screen.
Go back to where your script is running. It should have printed this message:
Hello from your own machine, Anvil Developer!
You’ve successfully connected your own machine to your Anvil app.
Click on the button below to clone a finished version of this app into your account.
A script that runs
anvil.server.connect() can do anything an Anvil Server Module can. It can:
- call functions in your Anvil Server Modules or in any other Uplink-connected script, using
- use Data Tables directly
- check which user is currently logged in
You can use the Uplink to connect to any environment that runs Python. That includes Jupyter Notebooks.
This means you’re not limited by what Anvil provides - you can do anything you can do on your own machine, and use Anvil’s features wherever they make life easier. Many people use Anvil as an add-on to their existing systems, to provide a UI or simple email client, for example.
You’re not even limited by what Python can achieve - a Python process makes the Uplink connection, but since Python can make system calls, you can launch any process you like from your Anvil app (great for automating machinery or running automated tests!)
Want more depth on this subject?
Read more about connecting your app to any external Python code.
Want another quickstart?
Every quickstart is on the Quickstarts page.