Calling functions remotely
You can call functions on your own machine (or anywhere else) using the Uplink, and you can call functions in your Anvil Server Modules from scripts on your own machine (or anywhere else).
Anvil -> your machine
To use the Anvil Uplink library in your Python project, first run pip install anvil-uplink
on your machine.
Your local Python code can now do anything a Server Module can do.
Mark functions with @anvil.server.callable
if you want to call them from your app.
# In a script on your own machine (or anywhere)
import anvil.server
anvil.server.connect("[YOUR UPLINK KEY]")
@anvil.server.callable
def get_file():
# Return a file from this local machine
return anvil.media.from_file("./image.jpg", "image/jpeg")
anvil.server.wait_forever()
Your machine -> Anvil
You can also call functions in your Anvil Server Modules from your uplinked code. This makes the Uplink a two-way connection.
# This is a simple program that makes a call to a server module.
import anvil.server
anvil.server.connect("[YOUR UPLINK KEY]")
anvil.server.call("store_number", 42)
This example does not register any @anvil.server.callable
functions, and exits as soon as the call to store_number
returns.
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.