Quickstart: Connect to code on your local machine
The Anvil Uplink lets you connect to Python code running anywhere and call Python functions directly from your app.
In this quickstart, you’ll create a simple function on your local machine and call it from your Anvil app.
Create an app
Log in to Anvil and click ‘Create a new app’. Choose the Material Design theme.
Enable the Uplink
Click the + button in the Sidebar Menu, and select Uplink:
Click the + button, then select Uplink
The Uplink window looks different depending on whether your app has one or multiple deployment environments:
For a single deployment environment: You will be prompted to choose between a Client Uplink and a Server Uplink. Click the Enable server Uplink button:
For multiple deployment environments: Click on the environment you want to connect the Uplink to, then click Enable next to Server Uplink Key:
Copy your Uplink key
Once enabled, Anvil generates a secret key. You will use this key to connect your external Python code to your application. Copy it to your clipboard:
Install the Uplink library
On your own computer, install the Uplink library (ensure you have Python installed).
pip install anvil-uplinkConnect a Python script to your app
On your computer, 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(f"Hello from your own machine, {name}!")
anvil.server.wait_forever()Replace the "<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
Call your local function from your app
Back in the Anvil Editor, close the Uplink dialog and click on ‘Code’ to see the Python code for Form1.
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 __init__ method.
At the end of the __init__ method, add this line to call the say_hello function in your hello.py script on your computer:
anvil.server.call('say_hello', 'Anvil Developer')Run your app
Now click the Run button at the top right of the screen:
Go back to where your script is running on your computer. It should have printed this message:
Hello from your own machine, Anvil Developer!
You’ve successfully connected your own machine to your Anvil app.
Copy the example app
Click on the button below to clone a finished version of this app into your account.
What you can do with the Uplink
A script that runs anvil.server.connect() can do anything an Anvil Server Module can. For example, it can:
- call functions in your Anvil Server Modules or in any other Uplink-connected script, using
anvil.server.call - use Data Tables directly
- check which user is currently logged in
You can connect the Uplink to any environment that runs Python, including Jupyter Notebooks.
This means you are not limited to what Anvil provides — you can use all the capabilities of your own machine or setup, while still benefiting from Anvil’s features. Many people use Anvil as an add-on to their existing systems, to provide a UI or simple email client.
The Uplink works by running a Python process on your machine that connects securely to your Anvil app. Because Python can make system calls, that process can trigger any program or action your machine can perform. This makes it possible to integrate with existing systems, control hardware, run automated tests, or launch other processes directly from your Anvil app.
Next up
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.
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.