id,page,ref,title,content,breadcrumbs,references
internals:bypassing-permission-checks,internals,bypassing-permission-checks,Bypassing permission checks,"All datasette.client methods accept an optional skip_permission_checks=True parameter. When set, all permission checks will be bypassed for that request, allowing access to any resource regardless of the configured permissions.
This is useful for plugins and internal operations that need to access all resources without being subject to permission restrictions.
Example usage:
# Regular request - respects permissions
response = await datasette.client.get(
""/private-db/secret-table.json""
)
# May return 403 Forbidden if access is denied
# With skip_permission_checks - bypasses all permission checks
response = await datasette.client.get(
""/private-db/secret-table.json"",
skip_permission_checks=True,
)
# Will return 200 OK and the data, regardless of permissions
This parameter works with all HTTP methods ( get , post , put , patch , delete , options , head ) and the generic request method.
Use skip_permission_checks=True with caution. It completely bypasses Datasette's permission system and should only be used in trusted plugin code or internal operations where you need guaranteed access to resources.","[""Internals for plugins"", ""Datasette class"", ""datasette.client""]",[]
internals:datasette-absolute-url,internals,datasette-absolute-url,".absolute_url(request, path)","request - Request
The current Request object
path - string
A path, for example /dbname/table.json
Returns the absolute URL for the given path, including the protocol and host. For example:
absolute_url = datasette.absolute_url(
request, ""/dbname/table.json""
)
# Would return ""http://localhost:8001/dbname/table.json""
The current request object is used to determine the hostname and protocol that should be used for the returned URL. The force_https_urls configuration setting is taken into account.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-actions,internals,datasette-actions,.actions,"Property exposing a dictionary of actions that have been registered using the register_actions(datasette) plugin hook.
The dictionary keys are the action names - e.g. view-instance - and the values are Action() objects describing the permission.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-actors-from-ids,internals,datasette-actors-from-ids,await .actors_from_ids(actor_ids),"actor_ids - list of strings or integers
A list of actor IDs to look up.
Returns a dictionary, where the keys are the IDs passed to it and the values are the corresponding actor dictionaries.
This method is mainly designed to be used with plugins. See the actors_from_ids(datasette, actor_ids) documentation for details.
If no plugins that implement that hook are installed, the default return value looks like this:
{
""1"": {""id"": ""1""},
""2"": {""id"": ""2""}
}","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-add-database,internals,datasette-add-database,".add_database(db, name=None, route=None)","db - datasette.database.Database instance
The database to be attached.
name - string, optional
The name to be used for this database . If not specified Datasette will pick one based on the filename or memory name.
route - string, optional
This will be used in the URL path. If not specified, it will default to the same thing as the name .
The datasette.add_database(db) method lets you add a new database to the current Datasette instance.
The db parameter should be an instance of the datasette.database.Database class. For example:
from datasette.database import Database
datasette.add_database(
Database(
datasette,
path=""path/to/my-new-database.db"",
)
)
This will add a mutable database and serve it at /my-new-database .
Use is_mutable=False to add an immutable database.
.add_database() returns the Database instance, with its name set as the database.name attribute. Any time you are working with a newly added database you should use the return value of .add_database() , for example:
db = datasette.add_database(
Database(datasette, memory_name=""statistics"")
)
await db.execute_write(
""CREATE TABLE foo(id integer primary key)""
)","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-add-memory-database,internals,datasette-add-memory-database,".add_memory_database(memory_name, name=None, route=None)","Adds a shared in-memory database with the specified name:
datasette.add_memory_database(""statistics"")
This is a shortcut for the following:
from datasette.database import Database
datasette.add_database(
Database(datasette, memory_name=""statistics"")
)
Using either of these patterns will result in the in-memory database being served at /statistics .
The name and route parameters are optional and work the same way as they do for .add_database(db, name=None, route=None) .","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-add-message,internals,datasette-add-message,".add_message(request, message, type=datasette.INFO)","request - Request
The current Request object
message - string
The message string
type - constant, optional
The message type - datasette.INFO , datasette.WARNING or datasette.ERROR
Datasette's flash messaging mechanism allows you to add a message that will be displayed to the user on the next page that they visit. Messages are persisted in a ds_messages cookie. This method adds a message to that cookie.
You can try out these messages (including the different visual styling of the three message types) using the /-/messages debugging tool.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-allowed,internals,datasette-allowed,"await .allowed(*, action, resource, actor=None)","action - string
The name of the action that is being permission checked.
resource - Resource object
A Resource object representing the database, table, or other resource. Must be an instance of a Resource class such as TableResource , DatabaseResource , QueryResource , or InstanceResource .
actor - dictionary, optional
The authenticated actor. This is usually request.actor . Defaults to None for unauthenticated requests.
This method checks if the given actor has permission to perform the given action on the given resource. All parameters must be passed as keyword arguments.
Example usage:
from datasette.resources import (
TableResource,
DatabaseResource,
)
# Check if actor can view a specific table
can_view = await datasette.allowed(
action=""view-table"",
resource=TableResource(
database=""fixtures"", table=""facetable""
),
actor=request.actor,
)
# Check if actor can execute SQL on a database
can_execute = await datasette.allowed(
action=""execute-sql"",
resource=DatabaseResource(database=""fixtures""),
actor=request.actor,
)
The method returns True if the permission is granted, False if denied.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-allowed-resources,internals,datasette-allowed-resources,"await .allowed_resources(action, actor=None, *, parent=None, include_is_private=False, include_reasons=False, limit=100, next=None)","Returns a PaginatedResources object containing resources that the actor can access for the specified action, with support for keyset pagination.
action - string
The action name (e.g., ""view-table"", ""view-database"")
actor - dictionary, optional
The authenticated actor. Defaults to None for unauthenticated requests.
parent - string, optional
Optional parent filter (e.g., database name) to limit results
include_is_private - boolean, optional
If True, adds a .private attribute to each Resource indicating whether anonymous users can access it
include_reasons - boolean, optional
If True, adds a .reasons attribute with a list of strings describing why access was granted (useful for debugging)
limit - integer, optional
Maximum number of results to return per page (1-1000, default 100)
next - string, optional
Keyset token from a previous page for pagination
The method returns a PaginatedResources object (from datasette.utils ) with the following attributes:
resources - list
List of Resource objects for the current page
next - string or None
Token for the next page, or None if no more results exist
Example usage:
# Get first page of tables
page = await datasette.allowed_resources(
""view-table"",
actor=request.actor,
parent=""fixtures"",
limit=50,
)
for table in page.resources:
print(table.parent, table.child)
if hasattr(table, ""private""):
print(f"" Private: {table.private}"")
# Get next page if available
if page.next:
next_page = await datasette.allowed_resources(
""view-table"", actor=request.actor, next=page.next
)
# Iterate through all results automatically
page = await datasette.allowed_resources(
""view-table"", actor=request.actor
)
async for table in page.all():
print(table.parent, table.child)
# With reasons for debugging
page = await datasette.allowed_resources(
""view-table"", actor=request.actor, include_reasons=True
)
for table in page.resources:
print(f""{table.child}: {table.reasons}"")
The page.all() async generator automatically handles pagination, fetching additional pages and yielding all resources one at a time.
This method uses await .allowed_resources_sql(*, action, actor=None, parent=None, include_is_private=False) under the hood and is an efficient way to list the databases, tables or other resources that an actor can access for a specific action.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-allowed-resources-sql,internals,datasette-allowed-resources-sql,"await .allowed_resources_sql(*, action, actor=None, parent=None, include_is_private=False)","Builds the SQL query that Datasette uses to determine which resources an actor may access for a specific action. Returns a (sql: str, params: dict) namedtuple that can be executed against the internal catalog_* database tables. parent can be used to limit results to a specific database, and include_is_private adds a column indicating whether anonymous users would be denied access to that resource.
Plugins that need to execute custom analysis over the raw allow/deny rules can use this helper to run the same query that powers the /-/allowed debugging interface.
The SQL query built by this method will return the following columns:
parent : The parent resource identifier (or NULL)
child : The child resource identifier (or NULL)
reason : The reason from the rule that granted access
is_private : (if include_is_private ) 1 if anonymous users cannot access, 0 otherwise","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-check-visibility,internals,datasette-check-visibility,"await .check_visibility(actor, action, resource=None)","actor - dictionary
The authenticated actor. This is usually request.actor .
action - string
The name of the action that is being permission checked.
resource - Resource object, optional
The resource being checked, as a Resource object such as DatabaseResource(database=...) , TableResource(database=..., table=...) , or QueryResource(database=..., query=...) . Only some permissions apply to a resource.
This convenience method can be used to answer the question ""should this item be considered private, in that it is visible to me but it is not visible to anonymous users?""
It returns a tuple of two booleans, (visible, private) . visible indicates if the actor can see this resource. private will be True if an anonymous user would not be able to view the resource.
This example checks if the user can access a specific table, and sets private so that a padlock icon can later be displayed:
from datasette.resources import TableResource
visible, private = await datasette.check_visibility(
request.actor,
action=""view-table"",
resource=TableResource(database=database, table=table),
)","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-column-types,internals,datasette-column-types,Column types,Column types are stored in the column_types table in the internal database . The following methods provide the API for reading and modifying column type assignments.,"[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-create-token,internals,datasette-create-token,"await .create_token(actor_id, expires_after=None, restrictions=None, handler=None)","actor_id - string
The ID of the actor to create a token for.
expires_after - int, optional
The number of seconds after which the token should expire.
restrictions - TokenRestrictions , optional
A TokenRestrictions object limiting which actions the token can perform.
handler - string, optional
The name of a specific token handler to use. If omitted, the first registered handler is used. See register_token_handler(datasette) .
This is an async method that returns an API token string which can be used to authenticate requests to the Datasette API. The default SignedTokenHandler returns tokens of the format dstok_... .
All tokens must have an actor_id string indicating the ID of the actor which the token will act on behalf of.
Tokens default to lasting forever, but can be set to expire after a given number of seconds using the expires_after argument. The following code creates a token for user1 that will expire after an hour:
token = await datasette.create_token(
actor_id=""user1"",
expires_after=3600,
)","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-databases,internals,datasette-databases,.databases,"Property exposing a collections.OrderedDict of databases currently connected to Datasette.
The dictionary keys are the name of the database that is used in the URL - e.g. /fixtures would have a key of ""fixtures"" . The values are Database class instances.
All databases are listed, irrespective of user permissions.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-ensure-permission,internals,datasette-ensure-permission,"await .ensure_permission(action, resource=None, actor=None)","action - string
The action to check. See Built-in actions for a list of available actions.
resource - Resource object (optional)
The resource to check the permission against. Must be an instance of InstanceResource , DatabaseResource , or TableResource from the datasette.resources module. If omitted, defaults to InstanceResource() for instance-level permissions.
actor - dictionary (optional)
The authenticated actor. This is usually request.actor .
This is a convenience wrapper around await .allowed(*, action, resource, actor=None) that raises a datasette.Forbidden exception if the permission check fails. Use this when you want to enforce a permission check and halt execution if the actor is not authorized.
Example:
from datasette.resources import TableResource
# Will raise Forbidden if actor cannot view the table
await datasette.ensure_permission(
action=""view-table"",
resource=TableResource(
database=""fixtures"", table=""cities""
),
actor=request.actor,
)
# For instance-level actions, resource can be omitted:
await datasette.ensure_permission(
action=""permissions-debug"", actor=request.actor
)","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-get-column-metadata,internals,datasette-get-column-metadata,"await .get_column_metadata(self, database_name, resource_name, column_name)","database_name - string
The name of the database to query.
resource_name - string
The name of the resource (table, view, or canned query) inside database_name to query.
column_name - string
The name of the column inside resource_name to query.
Returns metadata keys and values for the specified column, resource, and table as a dictionary.
Internally queries the metadata_columns table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-get-column-type,internals,datasette-get-column-type,"await .get_column_type(database, resource, column)","database - string
The name of the database.
resource - string
The name of the table or view.
column - string
The name of the column.
Returns a ColumnType subclass instance with .config populated for the specified column, or None if no column type is assigned.
ct = await datasette.get_column_type(
""mydb"", ""mytable"", ""email_col""
)
if ct:
print(ct.name) # ""email""
print(ct.config) # None or {...}","[""Internals for plugins"", ""Datasette class"", ""Column types""]",[]
internals:datasette-get-column-types,internals,datasette-get-column-types,"await .get_column_types(database, resource)","database - string
The name of the database.
resource - string
The name of the table or view.
Returns a dictionary mapping column names to ColumnType subclass instances (with .config populated) for all columns that have assigned types on the given resource.
ct_map = await datasette.get_column_types(""mydb"", ""mytable"")
for col_name, ct in ct_map.items():
print(col_name, ct.name, ct.config)","[""Internals for plugins"", ""Datasette class"", ""Column types""]",[]
internals:datasette-get-database,internals,datasette-get-database,.get_database(name),"name - string, optional
The name of the database - optional.
Returns the specified database object. Raises a KeyError if the database does not exist. Call this method without an argument to return the first connected database.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-get-database-metadata,internals,datasette-get-database-metadata,"await .get_database_metadata(self, database_name)","database_name - string
The name of the database to query.
Returns metadata keys and values for the specified database as a dictionary.
Internally queries the metadata_databases table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-get-instance-metadata,internals,datasette-get-instance-metadata,await .get_instance_metadata(self),"Returns metadata keys and values for the entire Datasette instance as a dictionary.
Internally queries the metadata_instance table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-get-resource-metadata,internals,datasette-get-resource-metadata,"await .get_resource_metadata(self, database_name, resource_name)","database_name - string
The name of the database to query.
resource_name - string
The name of the resource (table, view, or canned query) inside database_name to query.
Returns metadata keys and values for the specified ""resource"" as a dictionary.
A ""resource"" in this context can be a table, view, or canned query.
Internally queries the metadata_resources table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-get-set-metadata,internals,datasette-get-set-metadata,Getting and setting metadata,"Metadata about the instance, databases, tables and columns is stored in tables in Datasette's internal database . The following methods are the supported API for plugins to read and update that stored metadata.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-plugin-config,internals,datasette-plugin-config,".plugin_config(plugin_name, database=None, table=None)","plugin_name - string
The name of the plugin to look up configuration for. Usually this is something similar to datasette-cluster-map .
database - None or string
The database the user is interacting with.
table - None or string
The table the user is interacting with.
This method lets you read plugin configuration values that were set in datasette.yaml . See Writing plugins that accept configuration for full details of how this method should be used.
The return value will be the value from the configuration file - usually a dictionary.
If the plugin is not configured the return value will be None .","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-remove-column-type,internals,datasette-remove-column-type,"await .remove_column_type(database, resource, column)","database - string
The name of the database.
resource - string
The name of the table or view.
column - string
The name of the column.
Removes the column type assignment for the specified column.
await datasette.remove_column_type(
""mydb"", ""mytable"", ""location""
)","[""Internals for plugins"", ""Datasette class"", ""Column types""]",[]
internals:datasette-remove-database,internals,datasette-remove-database,.remove_database(name),"name - string
The name of the database to be removed.
This removes a database that has been previously added. name= is the unique name of that database.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-resolve-database,internals,datasette-resolve-database,.resolve_database(request),"request - Request object
A request object
If you are implementing your own custom views, you may need to resolve the database that the user is requesting based on a URL path. If the regular expression for your route declares a database named group, you can use this method to resolve the database object.
This returns a Database instance.
If the database cannot be found, it raises a datasette.utils.asgi.DatabaseNotFound exception - which is a subclass of datasette.utils.asgi.NotFound with a .database_name attribute set to the name of the database that was requested.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-resolve-row,internals,datasette-resolve-row,.resolve_row(request),"request - Request object
A request object
This method assumes your route declares named groups for database , table and pks .
It returns a ResolvedRow named tuple instance with the following fields:
db - Database
The database object
table - string
The name of the table
sql - string
SQL snippet that can be used in a WHERE clause to select the row
params - dict
Parameters that should be passed to the SQL query
pks - list
List of primary key column names
pk_values - list
List of primary key values decoded from the URL
row - sqlite3.Row
The row itself
If the database or table cannot be found it raises a datasette.utils.asgi.DatabaseNotFound exception.
If the table does not exist it raises a datasette.utils.asgi.TableNotFound exception.
If the row cannot be found it raises a datasette.utils.asgi.RowNotFound exception. This has .database_name , .table and .pk_values attributes, extracted from the request path.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-resolve-table,internals,datasette-resolve-table,.resolve_table(request),"request - Request object
A request object
This assumes that the regular expression for your route declares both a database and a table named group.
It returns a ResolvedTable named tuple instance with the following fields:
db - Database
The database object
table - string
The name of the table (or view)
is_view - boolean
True if this is a view, False if it is a table
If the database or table cannot be found it raises a datasette.utils.asgi.DatabaseNotFound exception.
If the table does not exist it raises a datasette.utils.asgi.TableNotFound exception - a subclass of datasette.utils.asgi.NotFound with .database_name and .table attributes.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-set-column-metadata,internals,datasette-set-column-metadata,"await .set_column_metadata(self, database_name, resource_name, column_name, key, value)","database_name - string
The database the metadata entry belongs to.
resource_name - string
The resource (table, view, or canned query) the metadata entry belongs to.
column-name - string
The column the metadata entry belongs to.
key - string
The metadata entry key to insert (ex title , description , etc.)
value - string
The value of the metadata entry to insert.
Adds a new metadata entry for the specified column.
Any previous column-level metadata entry with the same key will be overwritten.
Internally upserts the value into the the metadata_columns table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-set-column-type,internals,datasette-set-column-type,"await .set_column_type(database, resource, column, column_type, config=None)","database - string
The name of the database.
resource - string
The name of the table or view.
column - string
The name of the column.
column_type - string
The column type name to assign, e.g. ""email"" .
config - dict, optional
Optional configuration dict for the column type.
Assigns a column type to a column. Overwrites any existing assignment for that column.
Raises ValueError if the column type declares sqlite_types and the target column does not match one of those SQLite types.
await datasette.set_column_type(
""mydb"",
""mytable"",
""location"",
""point"",
config={""srid"": 4326},
)","[""Internals for plugins"", ""Datasette class"", ""Column types""]",[]
internals:datasette-set-database-metadata,internals,datasette-set-database-metadata,"await .set_database_metadata(self, database_name, key, value)","database_name - string
The database the metadata entry belongs to.
key - string
The metadata entry key to insert (ex title , description , etc.)
value - string
The value of the metadata entry to insert.
Adds a new metadata entry for the specified database.
Any previous database-level metadata entry with the same key will be overwritten.
Internally upserts the value into the the metadata_databases table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-set-instance-metadata,internals,datasette-set-instance-metadata,"await .set_instance_metadata(self, key, value)","key - string
The metadata entry key to insert (ex title , description , etc.)
value - string
The value of the metadata entry to insert.
Adds a new metadata entry for the entire Datasette instance.
Any previous instance-level metadata entry with the same key will be overwritten.
Internally upserts the value into the the metadata_instance table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-set-resource-metadata,internals,datasette-set-resource-metadata,"await .set_resource_metadata(self, database_name, resource_name, key, value)","database_name - string
The database the metadata entry belongs to.
resource_name - string
The resource (table, view, or canned query) the metadata entry belongs to.
key - string
The metadata entry key to insert (ex title , description , etc.)
value - string
The value of the metadata entry to insert.
Adds a new metadata entry for the specified ""resource"".
Any previous resource-level metadata entry with the same key will be overwritten.
Internally upserts the value into the the metadata_resources table inside the internal database .","[""Internals for plugins"", ""Datasette class"", ""Getting and setting metadata""]",[]
internals:datasette-setting,internals,datasette-setting,.setting(key),"key - string
The name of the setting, e.g. base_url .
Returns the configured value for the specified setting . This can be a string, boolean or integer depending on the requested setting.
For example:
downloads_are_allowed = datasette.setting(""allow_download"")","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-track-event,internals,datasette-track-event,await .track_event(event),"event - Event
An instance of a subclass of datasette.events.Event .
Plugins can call this to track events, using classes they have previously registered. See Event tracking for details.
The event will then be passed to all plugins that have registered to receive events using the track_event(datasette, event) hook.
Example usage, assuming the plugin has previously registered the BanUserEvent class:
await datasette.track_event(
BanUserEvent(user={""id"": 1, ""username"": ""cleverbot""})
)","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-unsign,internals,datasette-unsign,".unsign(value, namespace=""default"")","signed - any serializable type
The signed string that was created using .sign(value, namespace=""default"") .
namespace - string, optional
The alternative namespace, if one was used.
Returns the original, decoded object that was passed to .sign(value, namespace=""default"") . If the signature is not valid this raises a itsdangerous.BadSignature exception.","[""Internals for plugins"", ""Datasette class""]",[]
internals:datasette-verify-token,internals,datasette-verify-token,await .verify_token(token),"token - string
The token string to verify.
This is an async method that verifies an API token by trying each registered token handler in order. Returns an actor dictionary from the first handler that recognizes the token, or None if no handler accepts it.
actor = await datasette.verify_token(token)
if actor:
# Token was valid
print(actor[""id""])","[""Internals for plugins"", ""Datasette class""]",[]
internals:id1,internals,id1,TokenRestrictions,"The TokenRestrictions class uses a builder pattern to specify which actions a token is allowed to perform. Import it from datasette.tokens :
from datasette.tokens import TokenRestrictions
restrictions = (
TokenRestrictions()
.allow_all(""view-instance"")
.allow_all(""view-table"")
.allow_database(""docs"", ""view-query"")
.allow_resource(""docs"", ""attachments"", ""insert-row"")
.allow_resource(""docs"", ""attachments"", ""update-row"")
)
The builder methods are:
allow_all(action) - allow an action across all databases and resources
allow_database(database, action) - allow an action on a specific database
allow_resource(database, resource, action) - allow an action on a specific resource (table, SQL view or canned query ) within a database
Each method returns the TokenRestrictions instance so calls can be chained.
The following example creates a token that can access view-instance and view-table across everything, can additionally use view-query for anything in the docs database and is allowed to execute insert-row and update-row in the attachments table in that database:
token = await datasette.create_token(
actor_id=""user1"",
restrictions=(
TokenRestrictions()
.allow_all(""view-instance"")
.allow_all(""view-table"")
.allow_database(""docs"", ""view-query"")
.allow_resource(""docs"", ""attachments"", ""insert-row"")
.allow_resource(""docs"", ""attachments"", ""update-row"")
),
)","[""Internals for plugins"", ""Datasette class"", ""await .create_token(actor_id, expires_after=None, restrictions=None, handler=None)""]",[]
internals:id2,internals,id2,.get_internal_database(),Returns a database object for reading and writing to the private internal database .,"[""Internals for plugins"", ""Datasette class""]",[]
internals:internals-datasette-is-client,internals,internals-datasette-is-client,Detecting internal client requests,"datasette.in_client() - returns bool
Returns True if the current code is executing within a datasette.client request, False otherwise.
This method is useful for plugins that need to behave differently when called through datasette.client versus when handling external HTTP requests.
Example usage:
async def fetch_documents(datasette):
if not datasette.in_client():
return Response.text(
""Only available via internal client requests"",
status=403,
)
...
Note that datasette.in_client() is independent of skip_permission_checks . A request made through datasette.client will always have in_client() return True , regardless of whether skip_permission_checks is set.","[""Internals for plugins"", ""Datasette class"", ""datasette.client""]",[]
internals:internals-datasette-urls,internals,internals-datasette-urls,datasette.urls,"The datasette.urls object contains methods for building URLs to pages within Datasette. Plugins should use this to link to pages, since these methods take into account any base_url configuration setting that might be in effect.
datasette.urls.instance(format=None)
Returns the URL to the Datasette instance root page. This is usually ""/"" .
datasette.urls.path(path, format=None)
Takes a path and returns the full path, taking base_url into account.
For example, datasette.urls.path(""-/logout"") will return the path to the logout page, which will be ""/-/logout"" by default or /prefix-path/-/logout if base_url is set to /prefix-path/
datasette.urls.logout()
Returns the URL to the logout page, usually ""/-/logout""
datasette.urls.static(path)
Returns the URL of one of Datasette's default static assets, for example ""/-/static/app.css""
datasette.urls.static_plugins(plugin_name, path)
Returns the URL of one of the static assets belonging to a plugin.
datasette.urls.static_plugins(""datasette_cluster_map"", ""datasette-cluster-map.js"") would return ""/-/static-plugins/datasette_cluster_map/datasette-cluster-map.js""
datasette.urls.static(path)
Returns the URL of one of Datasette's default static assets, for example ""/-/static/app.css""
datasette.urls.database(database_name, format=None)
Returns the URL to a database page, for example ""/fixtures""
datasette.urls.table(database_name, table_name, format=None)
Returns the URL to a table page, for example ""/fixtures/facetable""
datasette.urls.query(database_name, query_name, format=None)
Returns the URL to a query page, for example ""/fixtures/pragma_cache_size""
These functions can be accessed via the {{ urls }} object in Datasette templates, for example:
Homepage
Fixtures database
facetable table
pragma_cache_size query
Use the format=""json"" (or ""csv"" or other formats supported by plugins) arguments to get back URLs to the JSON representation. This is the path with .json added on the end.
These methods each return a datasette.utils.PrefixedUrlString object, which is a subclass of the Python str type. This allows the logic that considers the base_url setting to detect if that prefix has already been applied to the path.","[""Internals for plugins"", ""Datasette class""]",[]