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():
  with open("./image.jpg") as f:
    return anvil.BlobMedia("image/jpeg", f.read())

anvil.server.wait_forever()

You 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.