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

anvil.server Module



Create a new ‘CallContext’ object

CallContext Attributes

client - anvil.server.CallContext.ClientInfo instance

An object that describes the client that initiated the current session. This can be a browser, an HTTP endpoint request, an uplink script, a background task, or an incoming email.

remote_caller - anvil.server.CallContext.StackFrame instance

An object describing the code that called this @anvil.server.callable function, where it was running, and whether it is trusted (server-side) or un-trusted (input from a browser, HTTP or other remote code)

type - string

The execution environment this code is running in. May be ‘browser’, ‘server_module’ or ‘uplink’


Create a new ‘CallContext.ClientInfo’ object

ClientInfo Attributes

ip - string

The IP address of the client that initiated this session.

location - anvil.server.CallContext.Location instance

The location of this client, as determined by its IP address, or None if it cannot be determined.

type - string

How this session was initiated. Valid values are: ‘browser’, ‘uplink’, ‘http’, ‘background_task’ and ‘email’.


Create a new ‘CallContext.Location’ object

Location Attributes

city - string

country - string

latitude - float

longitude - float

subdivision - string


Create a new ‘CallContext.StackFrame’ object

StackFrame Attributes

is_trusted - boolean

Was this code running in a trusted location (ie on the server side)?

type - string

The location of the calling code. Valid values are: ‘browser’, ‘server_module’, ‘uplink’ and ‘client_uplink’ for your app’s code, or ‘http’, ‘background_task’ or ‘email’ if this code was extrernally triggered.


Create a Capability object. Give it a list representing its scope - eg [“my_database”, “table_name”]. The scope of user-created Capabilities may not begin with “anvil”.



Instance Methods

narrow(additional_scope) → anvil.server.Capability instance

Return a new capability that is narrower than this one, by appending additional scope element(s) to it.


Send an update to the update handler for this capability, in this interpreter and also in any calling environment (eg browser code) that passed this capability into the current server function.

set_update_handler(apply_update, [get_update])

Set a handler for what happens when an update is sent to this capability.

Optionally provide a function for aggregating updates (default behaviour is to merge them, if they are all dictionaries, or to return only the most recent update otherwise.)

Capability Attributes

scope - list

A list representing what this capability represents. It can be extended by calling narrow(), but not shortened.

Eg: [‘my_resource’, 42, ‘foo’]


Create a new ‘HttpRequest’ object



HttpRequest Attributes

body - anvil.Media instance

The body of the HTTP request

body_json - dict

The decoded JSON body of the HTTP request, if applicable. Only available when Content-Type header is ‘application/json’.

form_params - dict

A dict of form parameters passed with this request.

headers - dict

HTTP headers sent with the current request

method - string

The HTTP method of the current request, e.g. GET, POST, etc.

origin - string

The origin of the current API request, e.g.

password - string

The password received through HTTP Basic Authentication

path - string

The path of the current request, e.g. /foo/bar

query_params - dict

A dict of query-string parameters passed with this request.

remote_address - string

The IP address the current request is coming from.

user - User

When require_auth is True, returns the row from the Users table corresponding to the authenticated user.

username - string

The username received through HTTP Basic Authentication


Create a new ‘HttpResponse’ object



HttpResponse Attributes

body - any

The body of this HTTP response. Can be a string, a Media object, or any JSON-able value.

headers - dict

The headers to return with this HTTP response. Content-Type will be set automatically if not specified.

status - number

The status code for this HTTP response. Default is 200.


get_api_origin([branch]#) → string

Returns the root URL of the API for the current app.

get_app_origin([branch]) → string

Returns the root URL of the current app.


Reset the current session to prevent further SessionExpiredErrors.



Contains information about what triggered the currently running code.


Use with anvil.server.no_loading_indicator: to suppress the loading indicator when making server calls


Contains information about the current HTTP API request.



Create a new ‘BackgroundTaskError’ object


Create a new ‘BackgroundTaskKilled’ object


Create a new ‘BackgroundTaskNotFound’ object


Create a new ‘ExecutionTerminatedError’ object


Create a new ‘InternalError’ object


Create a new ‘InvalidResponseError’ object


Create a new ‘NoServerFunctionError’ object


Create a new ‘QuotaExceededError’ object


Create a new ‘RuntimeUnavailableError’ object


Create a new ‘SerializationError’ object


Create a new ‘SessionExpiredError’ object


Create a new ‘TimeoutError’ object


Create a new ‘UplinkDisconnectedError’ object