til: datasette_datasette-on-replit.md
This data as json
| path | topic | title | url | body | html | shot | created | created_utc | updated | updated_utc | shot_hash | slug |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| datasette_datasette-on-replit.md | datasette | Running Datasette on Replit | https://github.com/simonw/til/blob/main/datasette/datasette-on-replit.md | I figured out how to run Datasette on https://replit.com/ The trick is to start a new Python project and then drop the following into the `main.py` file: ```python import uvicorn from datasette.app import Datasette ds = Datasette(memory=True, files=[]) if __name__ == "__main__": uvicorn.run(ds.app(), host="0.0.0.0", port=8000) ``` Replit is smart enough to automatically create a `pyproject.toml` file with `datasette` and `uvicorn` as dependencies. It will also notice that the application is running on port 8000 and set `https://name-of-prject.your-username.repl.co` to proxy to that port. Plus it will restart the server any time it recieves new traffic (and pause it in between groups of requests). To serve a database file, download it using `wget` in the Replit console and add it to the `files=[]` argument. I ran this: wget https://datasette.io/content.db Then changed that first line to: ```python ds = Datasette(files=["content.db"]) ``` And restarted the server. | <p>I figured out how to run Datasette on <a href="https://replit.com/" rel="nofollow">https://replit.com/</a></p> <p>The trick is to start a new Python project and then drop the following into the <code>main.py</code> file:</p> <div class="highlight highlight-source-python"><pre><span class="pl-k">import</span> <span class="pl-s1">uvicorn</span> <span class="pl-k">from</span> <span class="pl-s1">datasette</span>.<span class="pl-s1">app</span> <span class="pl-k">import</span> <span class="pl-v">Datasette</span> <span class="pl-s1">ds</span> <span class="pl-c1">=</span> <span class="pl-v">Datasette</span>(<span class="pl-s1">memory</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">files</span><span class="pl-c1">=</span>[]) <span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">"__main__"</span>: <span class="pl-s1">uvicorn</span>.<span class="pl-en">run</span>(<span class="pl-s1">ds</span>.<span class="pl-en">app</span>(), <span class="pl-s1">host</span><span class="pl-c1">=</span><span class="pl-s">"0.0.0.0"</span>, <span class="pl-s1">port</span><span class="pl-c1">=</span><span class="pl-c1">8000</span>)</pre></div> <p>Replit is smart enough to automatically create a <code>pyproject.toml</code> file with <code>datasette</code> and <code>uvicorn</code> as dependencies. It will also notice that the application is running on port 8000 and set <code>https://name-of-prject.your-username.repl.co</code> to proxy to that port. Plus it will restart the server any time it recieves new traffic (and pause it in between groups of requests).</p> <p>To serve a database file, download it using <code>wget</code> in the Replit console and add it to the <code>files=[]</code> argument. I ran this:</p> <pre><code>wget https://datasette.io/content.db </code></pre> <p>Then changed that first line to:</p> <div class="highlight highlight-source-python"><pre><span class="pl-s1">ds</span> <span class="pl-c1">=</span> <span class="pl-v">Datasette</span>(<span class="pl-s1">files</span><span class="pl-c1">=</span>[<span class="pl-s">"content.db"</span>])</pre></div> <p>And restarted the server.</p> | <Binary: 58,425 bytes> | 2021-05-02T11:50:05-07:00 | 2021-05-02T18:50:05+00:00 | 2021-05-02T11:50:05-07:00 | 2021-05-02T18:50:05+00:00 | 96e900155fbcb773fcc32dfbbc2bf55c | datasette-on-replit |