Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish SQLite database using Datasette
Browse files Browse the repository at this point in the history
amotl committed Jul 1, 2023
1 parent b44ce11 commit 016c053
Showing 6 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ pypi-upload: install-releasetools

install-package:
@test -e $(python) || python3 -m venv $(venv)
$(pip) install --prefer-binary --editable=.[test,develop,release,sql]
$(pip) install --prefer-binary --editable=.[test,sql,datasette,develop,release]

install-doctools:
@test -e $(python) || python3 -m venv $(venv)
13 changes: 13 additions & 0 deletions doc/export/sqlite.rst
Original file line number Diff line number Diff line change
@@ -95,6 +95,19 @@ Run a query on the ``dwd_phenology`` view.
For more example SQL statements, see also :ref:`SQLite DWD archive usage
<dwd-archive-usage>`.
datasette
---------
`Datasette`_ is a tool for exploring and publishing data. It helps people take data of
any shape or size and publish that as an interactive, explorable website and accompanying
API.
::
datasette serve --port 7777 *.sqlite
https://datasette.io/tutorials/explore
*******
Details
Empty file.
57 changes: 57 additions & 0 deletions phenodata/dwd/datasette_app/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import asyncio
import logging
from pathlib import Path

import uvicorn
from datasette.app import Datasette
from datasette.cli import check_databases
from datasette.utils import SpatialiteNotFound, StartupError


logger = logging.getLogger(__name__)

here = Path(__file__).parent


def main():
#datasette.cli.serve()

files = ["phenodata-dwd-annual-recent.sqlite"]
options = {"config_dir": here}
#print("options:", options)
#scsdc

try:
ds = Datasette(files, **options)
except SpatialiteNotFound:
raise IOError("Could not find SpatiaLite extension")
except StartupError as e:
raise IOError(e.args[0])

# Run the "startup" plugin hooks
asyncio.get_event_loop().run_until_complete(ds.invoke_startup())

# Run async soundness checks - but only if we're not under pytest
asyncio.get_event_loop().run_until_complete(check_databases(ds))

url = None
host = "localhost"
port = 7777

# Start the server
url = "http://{}:{}{}?token={}".format(
host, port, ds.urls.path("-/auth-token"), ds._root_token
)
logger.info(url)
uvicorn_kwargs = dict(
host=host, port=port, log_level="info", lifespan="on", workers=1
)

# Bind to a Unix domain socket
#if uds:
# uvicorn_kwargs["uds"] = uds
uvicorn.run(ds.app(), **uvicorn_kwargs)


if __name__ == "__main__":
main()
9 changes: 9 additions & 0 deletions phenodata/dwd/datasette_app/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cache_size_kb": 50000,
"default_cache_ttl": 86400,
"facet_time_limit_ms": 1000,
"force_https_urls": false,
"max_csv_mb": 500,
"num_sql_threads": 10,
"sql_time_limit_ms": 7420
}
17 changes: 17 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -86,6 +86,23 @@
zip_safe=False,
install_requires=requires,
extras_require={
'datasette': [
'datasette<1',
'datasette-atom<1',
'datasette-ics<1',
# 'datasette-configure-fts<2',
'datasette-cluster-map<1',
'datasette-copyable<1',
'datasette-dashboards<1',
'datasette-graphql<3',
'datasette-gzip<1',
'datasette-query-files<1',
'datasette-query-links<1',
#'datasette-redirect-to-https<1',
'datasette-search-all<2',
#'datasette-total-page-time<1', # Internal Server Error
'datasette-vega<1',
],
'sql': ['duckdb>=0.3,<0.8'],
'test': test_requires,
},

0 comments on commit 016c053

Please sign in to comment.