Call context provides information about where your code is running and where it was called from.
anvil.server.context object provides this information.
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>")
anvil.server.context.client object tells you about that client, including its
type (one of
For browsers and HTTP addresses, you can also find the IP address (
client.ip), and a geographical location estimated from that IP (
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!)
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
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!)