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.

anvil.server Module

Classes

Capability

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

Constructor

Capability(scope)

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.


Capability Attributes

narrow - narrow

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

scope - list

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

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


HttpRequest

Create a new ‘HttpRequest’ object

Constructor

HttpRequest()

HttpRequest Attributes

body - body

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. https://my-app.anvil.app/_/api

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


HttpResponse

Create a new ‘HttpResponse’ object

Constructor

HttpResponse()

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.


Functions

get_app_origin([branch]) → string

Returns the root URL of the current app.


reset_session()

Reset the current session to prevent further SessionExpiredErrors.


Globals

no_loading_indicator

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


request

Contains information about the current HTTP API request.


Exceptions

BackgroundTaskError

Create a new ‘BackgroundTaskError’ object


BackgroundTaskKilled

Create a new ‘BackgroundTaskKilled’ object


BackgroundTaskNotFound

Create a new ‘BackgroundTaskNotFound’ object


ExecutionTerminatedError

Create a new ‘ExecutionTerminatedError’ object


InternalError

Create a new ‘InternalError’ object


InvalidResponseError

Create a new ‘InvalidResponseError’ object


NoServerFunctionError

Create a new ‘NoServerFunctionError’ object


QuotaExceededError

Create a new ‘QuotaExceededError’ object


RuntimeUnavailableError

Create a new ‘RuntimeUnavailableError’ object


SerializationError

Create a new ‘SerializationError’ object


SessionExpiredError

Create a new ‘SessionExpiredError’ object


TimeoutError

Create a new ‘TimeoutError’ object


UplinkDisconnectedError

Create a new ‘UplinkDisconnectedError’ object