Let’s imagine we’ve been testing some marketing strategies, and we’ve collected data on the number of visits to our page for each strategy. But this data is held in a private SQL database that can only be accessed from within our company network.
We’ll use the Anvil Uplink as a gateway to give our app access to this data.
Connect your own machine to your Anvil app
The Anvil Uplink allows you to connect code running anywhere to your Anvil app. You can write code to query your private database, run it inside your company network, then use the Uplink to connect to your app – so now you can run your query from the cloud!
Let’s set it up. Start by selecting the Anvil Uplink in your app menu.
Click the green ‘Enable the Anvil Server Uplink for this app’ button, and you’ll see an authentication key that you can use to connect code running elsewhere to your Anvil app:
To use the Anvil uplink library in your Python project, first run
pip install anvil-uplink on your machine.
Then create a file called
my_uplink_script.py containing these lines:
import anvil.server anvil.server.connect('your-uplink-key')
(Remember to replace
'your-uplink-key' with the Uplink key for your app!)
Run the script (type
python my_uplink_script.py in a Terminal window). You’ll see the following lines in your Terminal window if the connection has been successful:
Connecting to wss://anvil.works/uplink Anvil websocket open Authenticated OK
That’s all you need to do to connect your machine to your Anvil app.