apple-notes-to-sqlite/README.md
# apple-notes-to-sqlite
[![PyPI](https://img.shields.io/pypi/v/apple-notes-to-sqlite.svg)](https://pypi.org/project/apple-notes-to-sqlite/)
[![Changelog](https://img.shields.io/github/v/release/dogsheep/apple-notes-to-sqlite?include_prereleases&label=changelog)](https://github.com/dogsheep/apple-notes-to-sqlite/releases)
[![Tests](https://github.com/dogsheep/apple-notes-to-sqlite/workflows/Test/badge.svg)](https://github.com/dogsheep/apple-notes-to-sqlite/actions?query=workflow%3ATest)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/dogsheep/apple-notes-to-sqlite/blob/master/LICENSE)
Export Apple Notes to SQLite
## Installation
Install this tool using `pip`:
pip install apple-notes-to-sqlite
## Usage
For help, run:
apple-notes-to-sqlite --help
You can also use:
python -m apple_notes_to_sqlite --help
To save your notes to a SQLite database called `notes.db` run:
apple-notes-to-sqlite notes.db
A progress bar will be shown.
You can stop it after a specified number of notes using `--stop-after`:
apple-notes-to-sqlite notes.db --stop-after 10
To dump the notes to standard output out as newline-delimited JSON, rather than saving them to a database, use the `--dump` option:
apple-notes-to-sqlite --dump
## Schema
The database schema generated by this tool looks like this:
<!-- [[[cog
import cog, json
from apple_notes_to_sqlite import cli
from click.testing import CliRunner
import sqlite_utils
import tempfile, pathlib
tmpdir = pathlib.Path(tempfile.mkdtemp())
db_path = str(tmpdir / "temp.db")
runner = CliRunner()
result = runner.invoke(cli.cli, [db_path, "--schema"])
cog.out("```sql\n")
cog.out(sqlite_utils.Database(db_path).schema)
cog.out("\n```")
]]] -->
```sql
CREATE TABLE [folders] (
[id] INTEGER PRIMARY KEY,
[long_id] TEXT,
[name] TEXT,
[parent] INTEGER,
FOREIGN KEY([parent]) REFERENCES [folders]([id])
);
CREATE TABLE [notes] (
[id] TEXT PRIMARY KEY,
[created] TEXT,
[updated] TEXT,
[folder] INTEGER,
[title] TEXT,
[body] TEXT,
FOREIGN KEY([folder]) REFERENCES [folders]([id])
);
CREATE UNIQUE INDEX [idx_folders_long_id]
ON [folders] ([long_id]);
```
<!-- [[[end]]] -->
### apple-notes-to-sqlite --help
<!-- [[[cog
import cog
from apple_notes_to_sqlite import cli
from click.testing import CliRunner
runner = CliRunner()
result = runner.invoke(cli.cli, ["--help"])
help = result.output.replace("Usage: cli", "Usage: apple-notes-to-sqlite")
cog.out(
"```\n{}\n```".format(help)
)
]]] -->
```
Usage: apple-notes-to-sqlite [OPTIONS] [DB_PATH]
Export Apple Notes to SQLite
Example usage:
apple-notes-to-sqlite notes.db
This will populate notes.db with 'notes' and 'folders' tables containing all
of your notes.
Options:
--version Show the version and exit.
--stop-after INTEGER Stop after this many notes
--dump Output notes to standard output
--schema Create database schema and exit
--help Show this message and exit.
```
<!-- [[[end]]] -->
## Development
To contribute to this tool, first checkout the code. Then create a new virtual environment:
cd apple-notes-to-sqlite
python -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest