Live Chat

We'll need to share your messages (and your email address if you're logged in) with our live chat provider, Drift. Here's their privacy policy.

If you don't want to do this, you can email us instead at contact@anvil.works.

Call Context

Call context provides information about where your code is running and where it was called from.

The anvil.server.context object provides this information.

Where your code is running

To check where your code is running, call anvil.server.context.type. For example:

if anvil.server.context.type == 'uplink':
  # We're on the Uplink, so connect to Anvil.
  anvil.server.connect("<my-app-key>")

Client information

Client information tells you about how the user is accessing your app – whether from a web browser, an HTTP endpoint, an incoming email, or an Uplink script.

The anvil.server.context.client object tells you about that client, including its type (one of "browser", "http", "email", "uplink", "client_uplink" or "background_task").

For browsers and HTTP addresses, you can also find the IP address (client.ip), and a geographical location estimated from that IP (client.location).

client is None when executing in the browser, or when executing on an Uplink but not as part of a server function. (In this situation, this code is the client!)

Remote caller

It’s also sometimes important to know how the current server function was called. For example, code in the web browser is not trustworthy, so it could pass us malicious arguments. anvil.server.context.remote_caller tells us about how this server function was called.

remote_caller.is_trusted is a boolean value that tells us whether we were called from trusted code – that is, a server module, background task or uplink.

remote_caller.type tells us exactly what type of code or event triggered this call (can be "browser", "server_module", "http", "email", "uplink", "client_uplink" or "background_task").

remote_caller is None when executing in the browser, or when executing on an Uplink but not as part of a server function. (This code was not called from anywhere!)