{"ok": true, "next": null, "rows": [{"id": "internals:internals-tilde-encoding", "page": "internals", "ref": "internals-tilde-encoding", "title": "Tilde encoding", "content": "Datasette uses a custom encoding scheme in some places, called  tilde encoding . This is primarily used for table names and row primary keys, to avoid any confusion between  /  characters in those values and the Datasette URLs that reference them. \n                 Tilde encoding uses the same algorithm as  URL percent-encoding , but with the  ~  tilde character used in place of  % . \n                 Any character other than  ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789_-  will be replaced by the numeric equivalent preceded by a tilde. For example: \n                 \n                     \n                         /  becomes  ~2F \n                     \n                     \n                         .  becomes  ~2E \n                     \n                     \n                         %  becomes  ~25 \n                     \n                     \n                         ~  becomes  ~7E \n                     \n                     \n                         Space becomes  + \n                     \n                     \n                         polls/2022.primary  becomes  polls~2F2022~2Eprimary \n                     \n                 \n                 Note that the space character is a special case: it will be replaced with a  +  symbol. \n                 \n                 \n                 \n                     datasette.utils. tilde_encode s :   str str \n                     \n                         Returns tilde-encoded string - for example  /foo/bar  ->  ~2Ffoo~2Fbar \n                     \n                 \n                 \n                 \n                 \n                     datasette.utils. tilde_decode s :   str str \n                     \n                         Decodes a tilde-encoded string, so  ~2Ffoo~2Fbar  ->  /foo/bar", "breadcrumbs": "[\"Internals for plugins\", \"The datasette.utils module\"]", "references": "[{\"href\": \"https://developer.mozilla.org/en-US/docs/Glossary/percent-encoding\", \"label\": \"URL percent-encoding\"}]"}, {"id": "internals:internals-utils-async-call-with-supported-arguments", "page": "internals", "ref": "internals-utils-async-call-with-supported-arguments", "title": "await async_call_with_supported_arguments(fn, ", "content": "Async version of  call_with_supported_arguments . Use this for  async def  callback functions. \n                 \n                 \n                     async   datasette.utils. async_call_with_supported_arguments fn ** kwargs \n                     \n                         Async version of  call_with_supported_arguments() . \n                         Calls  await fn(...)  with the subset of  **kwargs  matching its\n                            signature. \n                         \n                             \n                                 Parameters \n                                 \n                                     \n                                         \n                                             fn  -- An async callable \n                                         \n                                         \n                                             kwargs  -- All available keyword arguments \n                                         \n                                     \n                                 \n                             \n                             \n                                 Returns \n                                 \n                                     The return value of  await fn(...)", "breadcrumbs": "[\"Internals for plugins\", \"The datasette.utils module\"]", "references": "[]"}, {"id": "internals:internals-utils-await-me-maybe", "page": "internals", "ref": "internals-utils-await-me-maybe", "title": "await_me_maybe(value)", "content": "Utility function for calling  await  on a return value if it is awaitable, otherwise returning the value. This is used by Datasette to support plugin hooks that can optionally return awaitable functions. Read more about this function in  The \u201cawait me maybe\u201d pattern for Python asyncio . \n                 \n                 \n                     async   datasette.utils. await_me_maybe value :   Any Any \n                     \n                         If value is callable, call it. If awaitable, await it. Otherwise return it.", "breadcrumbs": "[\"Internals for plugins\", \"The datasette.utils module\"]", "references": "[{\"href\": \"https://simonwillison.net/2020/Sep/2/await-me-maybe/\", \"label\": \"The \u201cawait me maybe\u201d pattern for Python asyncio\"}]"}, {"id": "internals:internals-utils-call-with-supported-arguments", "page": "internals", "ref": "internals-utils-call-with-supported-arguments", "title": "call_with_supported_arguments(fn, ", "content": "Call  fn , passing it only those keyword arguments that match its function signature. This implements a dependency injection pattern - the caller provides all available arguments, and the function receives only the ones it declares as parameters. \n                 This is useful in plugins that want to define callback functions that only declare the arguments they need. For example: \n                 from datasette.utils import call_with_supported_arguments\n\n\ndef my_callback(request, datasette): ...\n\n\n# This will pass only request and datasette, ignoring other kwargs:\ncall_with_supported_arguments(\n    my_callback,\n    request=request,\n    datasette=datasette,\n    database=database,\n    table=table,\n) \n                 \n                 \n                     datasette.utils. call_with_supported_arguments fn ** kwargs \n                     \n                         Call  fn  with the subset of  **kwargs  matching its signature. \n                         This implements dependency injection: the caller provides all available\n                            keyword arguments and the function receives only the ones it declares\n                            as parameters. \n                         \n                             \n                                 Parameters \n                                 \n                                     \n                                         \n                                             fn  -- A callable (sync function) \n                                         \n                                         \n                                             kwargs  -- All available keyword arguments \n                                         \n                                     \n                                 \n                             \n                             \n                                 Returns \n                                 \n                                     The return value of  fn", "breadcrumbs": "[\"Internals for plugins\", \"The datasette.utils module\"]", "references": "[]"}, {"id": "internals:internals-utils-named-parameters", "page": "internals", "ref": "internals-utils-named-parameters", "title": "named_parameters(sql)", "content": "Derive the list of  :named  parameters referenced in a SQL query. \n                 \n                 \n                     datasette.utils. named_parameters sql :   str List [ str ] \n                     \n                         Given a SQL statement, return a list of named parameters that are used in the statement \n                         e.g. for  select * from foo where id=:id  this would return  [\"id\"]", "breadcrumbs": "[\"Internals for plugins\", \"The datasette.utils module\"]", "references": "[]"}, {"id": "internals:internals-utils-parse-metadata", "page": "internals", "ref": "internals-utils-parse-metadata", "title": "parse_metadata(content)", "content": "This function accepts a string containing either JSON or YAML, expected to be of the format described in  Metadata . It returns a nested Python dictionary representing the parsed data from that string. \n                 If the metadata cannot be parsed as either JSON or YAML the function will raise a  utils.BadMetadataError  exception. \n                 \n                 \n                     datasette.utils. parse_metadata content :   str dict \n                     \n                         Detects if content is JSON or YAML and parses it appropriately.", "breadcrumbs": "[\"Internals for plugins\", \"The datasette.utils module\"]", "references": "[]"}], "truncated": false}