ripgrep
dogsheep-beta/dogsheep_beta/__init__.py
57 from datasette.utils import path_with_removed_args, path_with_replaced_args
58
59 config = datasette.plugin_config("dogsheep-beta") or {}
60 database_name = config.get("database") or datasette.get_database().name
61 dogsheep_beta_config_file = config["config_file"]
datasette-upload-dbs/datasette_upload_dbs/__init__.py
52
53 def _configured(datasette):
54 return (datasette.plugin_config("datasette-upload-dbs") or {}).get("directory")
55
56
datasette-unsafe-expose-env/datasette_unsafe_expose_env/__init__.py
7
8 async def env(request, datasette):
9 redact = (datasette.plugin_config("datasette-unsafe-expose-env") or {}).get(
10 "redact"
11 ) or DEFAULT_REDACT
datasette-tiles/datasette_tiles/utils.py
32
33 async def tiles_stack_database_order(datasette):
34 config = datasette.plugin_config("datasette-tiles") or {}
35 stack_order = config.get("tiles-stack-order")
36 if not stack_order:
datasette-socrata/datasette_socrata/__init__.py
101
102 # Config can be used to restrict to a named database
103 config = datasette.plugin_config("datasette-socrata") or {}
104 configured_database = config.get("database")
105
datasette-sentry/datasette_sentry.py
6 @hookimpl
7 def asgi_wrapper(datasette):
8 config = datasette.plugin_config("datasette-sentry") or {}
9 dsn = config.get("dsn")
10 if dsn is not None:
datasette-seaborn/datasette_seaborn/__init__.py
28 }
29
30 plugin_config = datasette.plugin_config("datasette-seaborn") or {}
31 render_time_limit = plugin_config.get("render_time_limit") or DEFAULT_TIME_LIMIT
32
datasette-scale-to-zero/datasette_scale_to_zero/__init__.py
56
57 def get_config(datasette):
58 duration_s = (datasette.plugin_config("datasette-scale-to-zero") or {}).get(
59 "duration"
60 )
datasette-ripgrep/datasette_ripgrep/__init__.py
81 globs = [g.strip() for g in request.args.getlist("glob") if g.strip()]
82
83 config = datasette.plugin_config("datasette-ripgrep") or {}
84 time_limit = config.get("time_limit") or 1.0
85 max_lines = config.get("max_lines") or 2000
138 async def view_file(request, datasette):
139 await check_permission(request, datasette)
140 config = datasette.plugin_config("datasette-ripgrep") or {}
141 subpath = urllib.parse.unquote(request.url_vars["subpath"])
142 path = config.get("path")
datasette-ripgrep/README.md
17
18 - [with.\*AsyncClient](https://ripgrep.datasette.io/-/ripgrep?pattern=with.*AsyncClient) - regular expression search for `with.*AsyncClient`
19 - [.plugin_config, literal=on](https://ripgrep.datasette.io/-/ripgrep?pattern=.plugin_config\(&literal=on) - a non-regular expression search for `.plugin_config(`
20 - [with.\*AsyncClient glob=datasette/\*\*](https://ripgrep.datasette.io/-/ripgrep?pattern=with.*AsyncClient&glob=datasette%2F%2A%2A) - search for that pattern only within the `datasette/` top folder
21 - ["sqlite-utils\[">\] glob=setup.py](https://ripgrep.datasette.io/-/ripgrep?pattern=%22sqlite-utils%5B%22%3E%5D&glob=setup.py) - a regular expression search for packages that depend on either `sqlite-utils` or `sqlite-utils>=some-version`
datasette-render-markdown/datasette_render_markdown/__init__.py
16 should_convert = False
17 config = (
18 datasette.plugin_config(
19 "datasette-render-markdown", database=database, table=table
20 )
datasette-render-images/datasette_render_images.py
11 size_limit = DEFAULT_SIZE_LIMIT
12 if datasette:
13 plugin_config = datasette.plugin_config("datasette-render-images") or {}
14 size_limit = plugin_config.get("size_limit") or DEFAULT_SIZE_LIMIT
15 # Only act on byte columns
datasette-render-timestamps/datasette_render_timestamps/__init__.py
18 def render_cell(value, column, table, database, datasette):
19 config = (
20 datasette.plugin_config(
21 "datasette-render-timestamps", database=database, table=table
22 )
datasette-render-html/datasette_render_html.py
5 @hookimpl
6 def render_cell(value, column, table, database, datasette):
7 config = datasette.plugin_config(
8 "datasette-render-html", database=database, table=table
9 )
datasette-remote-metadata/datasette_remote_metadata/__init__.py
12 # when it hits time limit. If the time limit is hit it will still
13 # perform the update once the request has completed
14 config = datasette.plugin_config("datasette-remote-metadata") or {}
15 url = config.get("url")
16 if not url:
59 def asgi_wrapper(datasette):
60 # Refresh stale (over X seconds old) remote metadata on every request
61 config = datasette.plugin_config("datasette-remote-metadata") or {}
62 ttl = config.get("ttl") or 30
63
datasette-redirect-forbidden/datasette_redirect_forbidden/__init__.py
5 @hookimpl
6 def forbidden(datasette):
7 config = datasette.plugin_config("datasette-redirect-forbidden") or {}
8 redirect_to = config.get("redirect_to")
9 if redirect_to:
datasette-permissions-sql/datasette_permissions_sql/__init__.py
20 value = json.dumps(value, default=repr)
21 params["actor_{}".format(key)] = value
22 for rule in datasette.plugin_config("datasette-permissions-sql") or []:
23 sql = rule["sql"]
24 rule_action = rule.get("action")
datasette-notebook/datasette_notebook/__init__.py
101
102 def config_notebook(datasette):
103 config = datasette.plugin_config("datasette-notebook") or {}
104 return config.get("database") or "notebook"
datasette-mask-columns/datasette_mask_columns/__init__.py
9 return sqlite3.SQLITE_OK
10 masks = (
11 datasette.plugin_config("datasette-mask-columns", database=database) or {}
12 )
13 columns_to_mask = masks.get(table) or None
29 @hookimpl()
30 def render_cell(column, table, database, datasette):
31 masks = datasette.plugin_config("datasette-mask-columns", database=database) or {}
32 columns_to_mask = masks.get(table) or set()
33 if column in columns_to_mask:
datasette-media/datasette_media/__init__.py
22 async def serve_media(datasette, request, send):
23 global transform_executor
24 plugin_config = datasette.plugin_config("datasette-media") or {}
25 pool_size = plugin_config.get("transform_threads") or 4
26 if transform_executor is None:
datasette-leaflet-geojson/datasette_leaflet_geojson/__init__.py
61 def extra_body_script(datasette, database, table):
62 config = (
63 datasette.plugin_config(
64 "datasette-leaflet-geojson", database=database, table=table
65 )
datasette-insert/datasette_insert/__init__.py
100 if action != "insert:all":
101 return None
102 plugin_config = datasette.plugin_config("datasette-insert") or {}
103 if "allow" in plugin_config:
104 return actor_matches_allow(actor, plugin_config["allow"])
datasette-indieauth/datasette_indieauth/__init__.py
230 if action != "view-instance":
231 return None
232 plugin_config = datasette.plugin_config("datasette-indieauth") or {}
233 if plugin_config.get("restrict_access") is None:
234 return None
datasette-init/datasette_init/__init__.py
6 def startup(datasette):
7 async def inner():
8 config = datasette.plugin_config("datasette-init")
9 if not config:
10 return
datasette-hashed-urls/datasette_hashed_urls/__init__.py
109 return
110 else:
111 plugin_config = datasette.plugin_config("datasette-hashed-urls") or {}
112 max_age = plugin_config.get("max_age", 31536000)
113
datasette-graphql/datasette_graphql/utils.py
235 schema=graphene.Schema(
236 query=Query,
237 auto_camelcase=(datasette.plugin_config("datasette-graphql") or {}).get(
238 "auto_camelcase", False
239 ),
360 fks_by_column = {fk.column: fk for fk in meta.foreign_keys}
361
362 table_plugin_config = datasette.plugin_config(
363 "datasette-graphql", database=db.name, table=table
364 )
datasette-graphql/datasette_graphql/__init__.py
103 )
104
105 config = datasette.plugin_config("datasette-graphql") or {}
106 context = {
107 "time_started": time.monotonic(),
192 def startup(datasette):
193 # Validate configuration
194 config = datasette.plugin_config("datasette-graphql") or {}
195 if "databases" in config:
196 for database_name in config["databases"].keys():
datasette-edit-templates/datasette_edit_templates/__init__.py
50
51 def get_database(datasette):
52 plugin_config = datasette.plugin_config("datasette-edit-templates") or {}
53 return datasette.get_database(plugin_config.get("database"))
54
datasette-cors/datasette_cors.py
5 @hookimpl
6 def asgi_wrapper(datasette):
7 config = datasette.plugin_config("datasette-cors") or {}
8 allow_all = config.get("allow_all") or False
9 hosts = config.get("hosts") or []
datasette-copy-to-memory/datasette_copy_to_memory/__init__.py
5 @hookimpl
6 def startup(datasette):
7 plugin_config = datasette.plugin_config("datasette-copy-to-memory") or {}
8 databases = plugin_config.get("databases")
9 replace = plugin_config.get("replace")
datasette-configure-asgi/datasette_configure_asgi.py
6 def asgi_wrapper(datasette):
7 def wrap_with_classes(app):
8 configs = datasette.plugin_config("datasette-configure-asgi") or []
9 for config in configs:
10 module_path, class_name = config["class"].rsplit(".", 1)
datasette-cluster-map/datasette_cluster_map/__init__.py
30 return []
31 config = (
32 datasette.plugin_config("datasette-cluster-map", database=database, table=table)
33 or {}
34 )
76 columns = [column.lower() for column in columns]
77 config = (
78 datasette.plugin_config("datasette-cluster-map", database=database, table=table)
79 or {}
80 )
datasette-block-robots/datasette_block_robots/__init__.py
4
5 def robots_txt(datasette):
6 config = datasette.plugin_config("datasette-block-robots") or {}
7 literal = config.get("literal")
8 disallow = []
32 @hookimpl
33 def startup(datasette):
34 config = datasette.plugin_config("datasette-block-robots") or {}
35 assert not (
36 config.get("disallow") and config.get("literal")
datasette-block/datasette_block/__init__.py
5 @hookimpl
6 def asgi_wrapper(datasette):
7 config = datasette.plugin_config("datasette-block") or {}
8 prefixes = config.get("prefixes") or []
9
datasette-auth0/datasette_auth0/__init__.py
106
107 def _config(datasette):
108 config = datasette.plugin_config("datasette-auth0")
109 missing = [
110 key for key in ("domain", "client_id", "client_secret") if not config.get(key)
datasette-auth-passwords/datasette_auth_passwords/utils.py
29
30 def scope_has_valid_authorization(scope, datasette):
31 config = datasette.plugin_config("datasette-auth-passwords") or {}
32 accounts = {
33 key.split("_password_hash")[0]: value
datasette-auth-passwords/datasette_auth_passwords/__init__.py
25
26 async def password_login(request, datasette):
27 config = datasette.plugin_config("datasette-auth-passwords") or {}
28 accounts = {
29 key.split("_password_hash")[0]: value
66 @hookimpl
67 def asgi_wrapper(datasette):
68 config = datasette.plugin_config("datasette-auth-passwords") or {}
69 if not config.get("http_basic_auth"):
70 return lambda asgi: asgi
datasette-auth-tokens/datasette_auth_tokens/__init__.py
6 def actor_from_request(datasette, request):
7 async def inner():
8 config = datasette.plugin_config("datasette-auth-tokens") or {}
9 allowed_tokens = config.get("tokens") or []
10 query_param = config.get("param")
datasette-auth-existing-cookies/datasette_auth_existing_cookies/__init__.py
6 @hookimpl
7 def actor_from_request(datasette, request):
8 config = datasette.plugin_config("datasette-auth-existing-cookies") or {}
9 api_url = config.get("api_url")
10 if api_url is None:
datasette-auth-github/datasette_auth_github/views.py
15
16 async def github_auth_start(datasette):
17 config = datasette.plugin_config("datasette-auth-github")
18 verify_config(config)
19 if config.get("load_teams") or config.get("load_orgs"):
39
40 async def github_auth_callback(datasette, request, scope, receive, send):
41 config = datasette.plugin_config("datasette-auth-github")
42 verify_config(config)
43 if not request.args.get("code"):
datasette-atom/datasette_atom/__init__.py
51 if query_name:
52 # Check allow_unsafe_html_in_canned_queries
53 plugin_config = datasette.plugin_config("datasette-atom")
54 if plugin_config:
55 allow_unsafe_html_in_canned_queries = plugin_config.get(
datasette/tests/test_plugins.py
53 )
54 assert [
55 "database=fixtures, datasette.plugin_config(\"name-of-plugin\")={'depth': 'root'}"
56 ] == response.json
57
199
200 def test_plugin_config(app_client):
201 assert {"depth": "table"} == app_client.ds.plugin_config(
202 "name-of-plugin", database="fixtures", table="sortable"
203 )
204 assert {"depth": "database"} == app_client.ds.plugin_config(
205 "name-of-plugin", database="fixtures", table="unknown_table"
206 )
207 assert {"depth": "database"} == app_client.ds.plugin_config(
208 "name-of-plugin", database="fixtures"
209 )
210 assert {"depth": "root"} == app_client.ds.plugin_config(
211 "name-of-plugin", database="unknown_database"
212 )
213 assert {"depth": "root"} == app_client.ds.plugin_config("name-of-plugin")
214 assert None is app_client.ds.plugin_config("unknown-plugin")
215
216
217 def test_plugin_config_env(app_client):
218 os.environ["FOO_ENV"] = "FROM_ENVIRONMENT"
219 assert {"foo": "FROM_ENVIRONMENT"} == app_client.ds.plugin_config("env-plugin")
220 # Ensure secrets aren't visible in /-/metadata.json
221 metadata = app_client.get("/-/metadata.json")
226 def test_plugin_config_env_from_list(app_client):
227 os.environ["FOO_ENV"] = "FROM_ENVIRONMENT"
228 assert [{"in_a_list": "FROM_ENVIRONMENT"}] == app_client.ds.plugin_config(
229 "env-plugin-list"
230 )
240 with open(TEMP_PLUGIN_SECRET_FILE, "w") as fp:
241 fp.write("FROM_FILE")
242 assert {"foo": "FROM_FILE"} == app_client.ds.plugin_config("file-plugin")
243 # Ensure secrets aren't visible in /-/metadata.json
244 metadata = app_client.get("/-/metadata.json")
datasette/tests/plugins/my_plugin_2.py
173 @hookimpl
174 def register_routes(datasette):
175 config = datasette.plugin_config("register-route-demo")
176 if not config:
177 return
datasette/tests/plugins/my_plugin.py
21
22 def prepare_connection_args():
23 return 'database={}, datasette.plugin_config("name-of-plugin")={}'.format(
24 database, datasette.plugin_config("name-of-plugin")
25 )
26
79 "database": database,
80 "table": table,
81 "config": datasette.plugin_config(
82 "name-of-plugin",
83 database=database,
108 "table": table,
109 "database": database,
110 "config": datasette.plugin_config(
111 "name-of-plugin",
112 database=database,
datasette/docs/writing_plugins.rst
177 When you are writing plugins, you can access plugin configuration like this using the ``datasette plugin_config()`` method. If you know you need plugin configuration for a specific table, you can access it like this::
178
179 plugin_config = datasette.plugin_config(
180 "datasette-cluster-map", database="sf-trees", table="Street_Tree_List"
181 )
datasette/docs/plugin_hooks.rst
35
36 ``datasette`` - :ref:`internals_datasette`
37 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
38
39 This hook is called when a new SQLite database connection is created. You can
112
113 ``datasette`` - :ref:`internals_datasette`
114 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
115
116 This hook can return one of three different types:
290 The ``template``, ``database``, ``table`` and ``view_name`` options can be used to return different code depending on which template is being rendered and which database or table are being processed.
291
292 The ``datasette`` instance is provided primarily so that you can consult any plugin configuration options that may have been set, using the ``datasette.plugin_config(plugin_name)`` method documented above.
293
294 This function can return a string containing JavaScript, or a dictionary as described below, or a function or awaitable function that returns a string or dictionary.
392
393 ``datasette`` - :ref:`internals_datasette`
394 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
395
396 If your hook returns ``None``, it will be ignored. Use this to indicate that your hook is not able to custom render this particular value.
458
459 ``datasette`` - :ref:`internals_datasette`
460 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
461
462 Registers a new output renderer, to output data in a custom format. The hook function should return a dictionary, or a list of dictionaries, of the following shape:
567
568 ``datasette`` - :ref:`internals_datasette`
569 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``
570
571 Register additional view functions to execute for specified URL routes.
595
596 ``datasette`` - :ref:`internals_datasette`
597 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
598
599 ``request`` - Request object
816 @hookimpl
817 def startup(datasette):
818 config = datasette.plugin_config("my-plugin") or {}
819 assert (
820 "required-setting" in config
864
865 ``datasette`` - :ref:`internals_datasette`
866 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
867
868 ``database`` - string
943
944 ``datasette`` - :ref:`internals_datasette`
945 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
946
947 ``request`` - object
1018
1019``datasette`` - :ref:`internals_datasette`
1020 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1021
1022This hook runs on the :ref:`table <TableView>` page, and can influence the ``where`` clause of the SQL query used to populate that page, based on query string arguments on the incoming request.
1067
1068``datasette`` - :ref:`internals_datasette`
1069 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1070
1071``actor`` - dictionary
1132
1133``datasette`` - :ref:`internals_datasette`
1134 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``.
1135
1136:ref:`canned_queries_magic_parameters` can be used to add automatic parameters to :ref:`canned queries <canned_queries>`. This plugin hook allows additional magic parameters to be defined by plugins.
1174
1175``datasette`` - :ref:`internals_datasette`
1176 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1177
1178``request`` - object
1225
1226``datasette`` - :ref:`internals_datasette`
1227 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1228
1229``actor`` - dictionary or None
1268
1269``datasette`` - :ref:`internals_datasette`
1270 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1271
1272``actor`` - dictionary or None
1315
1316``datasette`` - :ref:`internals_datasette`
1317 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1318
1319``actor`` - dictionary or None
1336
1337``datasette`` - :ref:`internals_datasette`
1338 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``, or to execute SQL queries.
1339
1340``scope`` - dictionary
1362
1363``datasette`` - :ref:`internals_datasette`
1364 You can use this to access plugin configuration options via ``datasette.plugin_config(your_plugin_name)``.
1365
1366``actor`` - dictionary or None
datasette/docs/internals.rst
275 .. _datasette_plugin_config:
276
277 .plugin_config(plugin_name, database=None, table=None)
278 ------------------------------------------------------
279