sqlite-utils/README.md

68 lines
2.7 KiB
Markdown
Raw Normal View History

2018-07-13 20:56:21 -07:00
# sqlite-utils
2018-07-31 08:38:50 -07:00
[![PyPI](https://img.shields.io/pypi/v/sqlite-utils.svg)](https://pypi.org/project/sqlite-utils/)
2020-04-30 11:32:23 -07:00
[![Changelog](https://img.shields.io/github/v/release/simonw/sqlite-utils?include_prereleases&label=changelog)](https://sqlite-utils.readthedocs.io/en/stable/changelog.html)
2020-08-28 15:41:29 -07:00
[![Tests](https://github.com/simonw/sqlite-utils/workflows/Test/badge.svg)](https://github.com/simonw/sqlite-utils/actions?query=workflow%3ATest)
2018-07-31 08:38:50 -07:00
[![Documentation Status](https://readthedocs.org/projects/sqlite-utils/badge/?version=latest)](http://sqlite-utils.readthedocs.io/en/latest/?badge=latest)
2020-08-10 14:04:32 -07:00
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/sqlite-utils/blob/main/LICENSE)
2018-07-31 08:38:50 -07:00
2019-01-25 18:21:55 -08:00
Python CLI utility and library for manipulating SQLite databases.
2019-02-24 19:45:38 -08:00
Read more on my blog: [
sqlite-utils: a Python library and CLI tool for building SQLite databases](https://simonwillison.net/2019/Feb/25/sqlite-utils/)
2020-04-17 16:59:47 -07:00
## Installation
2018-07-31 08:38:50 -07:00
2020-05-11 12:23:11 -07:00
pip install sqlite-utils
2018-07-31 08:38:50 -07:00
2020-04-17 16:59:47 -07:00
## Using as a CLI tool
2019-07-03 11:04:03 -07:00
Now you can do things with the CLI utility like this:
2019-01-25 18:21:55 -08:00
$ sqlite-utils tables dogs.db --counts
[{"table": "dogs", "count": 2}]
2019-01-25 18:21:55 -08:00
$ sqlite-utils dogs.db "select * from dogs"
[{"id": 1, "age": 4, "name": "Cleo"},
{"id": 2, "age": 2, "name": "Pancakes"}]
$ sqlite-utils dogs.db "select * from dogs" --csv
2019-01-25 18:21:55 -08:00
id,age,name
1,4,Cleo
2,2,Pancakes
2019-02-24 15:11:51 -08:00
$ sqlite-utils dogs.db "select * from dogs" --table
id age name
---- ----- --------
1 4 Cleo
2 2 Pancakes
2020-04-17 16:59:47 -07:00
You can even import data into a new database table like this:
$ curl https://api.github.com/repos/simonw/sqlite-utils/releases \
| sqlite-utils insert releases.db releases - --pk
Full CLI documentation: https://sqlite-utils.readthedocs.io/en/stable/cli.html
## Using as a library
You can also `import sqlite_utils` and use it as a Python library like this:
2019-07-03 11:04:03 -07:00
```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")
```
2020-04-17 16:59:47 -07:00
Full library documentation: https://sqlite-utils.readthedocs.io/en/stable/python-api.html
2018-07-31 08:38:50 -07:00
2020-04-17 16:59:47 -07:00
## Related projects
2018-07-31 08:38:50 -07:00
* [Datasette](https://github.com/simonw/datasette): A tool for exploring and publishing data
* [csvs-to-sqlite](https://github.com/simonw/csvs-to-sqlite): Convert CSV files into a SQLite database
* [db-to-sqlite](https://github.com/simonw/db-to-sqlite): CLI tool for exporting a MySQL or PostgreSQL database as a SQLite file
2020-04-17 16:59:47 -07:00
* [dogsheep](https://dogsheep.github.io/): A family of tools for personal analytics, built on top of `sqlite-utils`