TIL Configure datasette to automatically assign an available port
Getting a working Datasette Web interface with something as simple as
datasette whatever.db is awesome!
This defaults to
localhost:8001. Every time. If you are using Datasette a lot, you might run
datasette cats.db and see:
ERROR: [Errno 48] error while attempting to bind on address ('127.0.0.1', 8001): address already in use
datasette is really useful.
- When you run
datasettedefaults to the
servesubcommand so it effectively runs
datasette serve my.db.
datasette serve --help, we learn about the
--port option. While that would be pretty straightforward to guess, there's a further reward for reading the docs:
Use -p 0 to automatically assign an available port.
We can use something like this to make sure
datasette finds a usable port and uses it:
datasette -p 0 cats.db
ℹ️ About this TIL snippet: Created 2022-12-27T19:02:58-05:00 · View the source