You are currently viewing the new Anvil Editor Docs.
Switch to the Classic Editor Docs
You are currently viewing the Classic Editor Docs.
Switch to the new Anvil Editor Docs

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()
If you connect multiple uplink programs that contain the same function name to the same app, then calls can be received by either uplink program.

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.