Added Python library example to README

This commit is contained in:
Simon Willison 2019-07-03 11:04:03 -07:00 committed by GitHub
commit 1a053d9438
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,7 +14,7 @@ Install it like this:
pip3 install sqlite-utils
Now you can do things like this:
Now you can do things with the CLI utility like this:
$ sqlite-utils tables dogs.db --counts
[{"table": "dogs", "count": 2}]
@ -34,6 +34,18 @@ Now you can do things like this:
1 4 Cleo
2 2 Pancakes
Or you can import it and use it as a Python library like this:
```python
import sqlite_utils
db = sqlite_utils.Database("demo_database.db")
# This line creates a "dogs" table if one does not already exist:
db["dogs"].insert_all([
{"id": 1, "age": 4, "name": "Cleo"},
{"id": 2, "age": 2, "name": "Pancakes"}
], pk="id")
```
Full documentation: https://sqlite-utils.readthedocs.io/
Related projects: