home / docs / sections

sections: internals:datasette-allowed-resources

This data as json

id page ref title content breadcrumbs references
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"] []
Powered by Datasette · Queries took 2.121ms