From 1a053d9438cb217e54e7784777e11620ece8fed0 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Wed, 3 Jul 2019 11:04:03 -0700 Subject: [PATCH] Added Python library example to README --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93bc3a8..1e41cfb 100644 --- a/README.md +++ b/README.md @@ -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: