trilium-py


Nametrilium-py JSON
Version 0.9.6 PyPI version JSON
download
home_pagehttps://github.com/nriver/trilium-py
SummaryPython client for ETAPI of Trilium Note. With some extra features powered by Python :)
upload_time2024-06-11 02:03:52
maintainerNone
docs_urlNone
authorNriver
requires_python<4,>=3.9
licenseNone
keywords trilium etapi api client
VCS
bugtrack_url
requirements requests BeautifulSoup4 python-magic python-magic python-magic-bin markdown2 natsort loguru minify-html pillow
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ๐Ÿ trilium-py

<p align="center">
English | <a href="README_CN.md">็ฎ€ไฝ“ไธญๆ–‡</a>
</p>

Python client for ETAPI of Trilium Note.

[![Downloads](https://static.pepy.tech/badge/trilium-py)](https://pepy.tech/project/trilium-py)
[![Supported Versions](https://img.shields.io/pypi/pyversions/trilium-py.svg)](https://pypi.org/project/trilium-py)
[![Supported Versions](https://img.shields.io/pypi/v/trilium-py?color=%2334D058&label=pypi%20package)](https://pypi.org/project/trilium-py)
[![PyPI license](https://img.shields.io/pypi/l/trilium-py.svg)](https://pypi.python.org/pypi/trilium-py/)
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)

## ๐Ÿฆฎ Table of Contents

<!--ts-->

* [๐Ÿ trilium-py](#-trilium-py)
    * [๐Ÿฆฎ Table of Contents](#-table-of-contents)
    * [๐Ÿ”ง Installation](#-installation)
    * [๐Ÿ“– (Basic) Usage](#-basic-usage)
        * [๐Ÿš€ Initialization](#-initialization)
        * [๐Ÿ“Š Application Information](#-application-information)
        * [๐Ÿ” Search note](#-search-note)
        * [๐Ÿญ Create Note](#-create-note)
            * [๐Ÿ–ผ๏ธ Create Image note](#๏ธ-create-image-note)
        * [๐Ÿ‘€ Get note](#-get-note)
        * [๐Ÿ”„ Update note](#-update-note)
        * [๐Ÿ—‘๏ธ Delete note](#๏ธ-delete-note)
        * [๐Ÿ“… Day note](#-day-note)
        * [๐Ÿ“ค Export note](#-export-note)
        * [๐Ÿ“ฅ import note](#-import-note)
        * [๐Ÿ’พ Save revision](#-save-revision)
        * [๐Ÿ’พ Create data backup](#-create-data-backup)
        * [๐Ÿท Create attribute](#-create-attribute)
        * [Get attachment list](#get-attachment-list)
        * [Get attachment info](#get-attachment-info)
        * [Update attachment info](#update-attachment-info)
        * [Get attachment content](#get-attachment-content)
        * [Update attachment content](#update-attachment-content)
        * [Create attachment](#create-attachment)
    * [(Advanced Usage) โœ… TODO List](#advanced-usage--todo-list)
        * [Add TODO item](#add-todo-item)
        * [Check/Uncheck a TODO item](#checkuncheck-a-todo-item)
        * [Update a TODO item](#update-a-todo-item)
        * [Delete a TODO item](#delete-a-todo-item)
        * [Move yesterday's unfinished todo to today](#move-yesterdays-unfinished-todo-to-today)
    * [(Advanced Usage) ๐Ÿšš Upload Markdown files](#advanced-usage--upload-markdown-files)
        * [Upload single Markdown file with images](#upload-single-markdown-file-with-images)
        * [Bulk upload Markdown files in a folder](#bulk-upload-markdown-files-in-a-folder)
            * [Import from VNote](#import-from-vnote)
            * [Import from Joplin](#import-from-joplin)
            * [Import from Logseq](#import-from-logseq)
            * [Import from Obsidian](#import-from-obsidian)
            * [Import from Youdao Note/ๆœ‰้“ไบ‘็ฌ”่ฎฐ](#import-from-youdao-noteๆœ‰้“ไบ‘็ฌ”่ฎฐ)
            * [Import from Turtl](#import-from-turtl)
            * [Import from other markdown software](#import-from-other-markdown-software)
    * [(Advanced Usage) ๐ŸŽจ Beautify notes](#advanced-usage--beautify-notes)
        * [Beautify a note](#beautify-a-note)
        * [Beautify a note and its child notes](#beautify-a-note-and-its-child-notes)
    * [(Advanced Usage) ๐Ÿงน Sort note content](#advanced-usage--sort-note-content)
    * [(Advanced Usage) ๐Ÿงน Delete empty new note](#advanced-usage--delete-empty-new-note)
    * [(Advanced Usage) ๐Ÿ—œ๏ธ Optimize image size](#advanced-usage-๏ธ-optimize-image-size)
    * [๐Ÿ› ๏ธ Develop](#๏ธ-develop)
    * [๐Ÿ”— Original OpenAPI Documentation](#-original-openapi-documentation)

<!--te-->

## ๐Ÿ”ง Installation

```bash
python3 -m pip install trilium-py --user
```

## ๐Ÿ“– (Basic) Usage

These are basic function that Trilium's ETAPI provides. Down below are some simple example code to use this package.

### ๐Ÿš€ Initialization

If you have a ETAPI token, change the `server_url` and `token` to yours.

```python
from trilium_py.client import ETAPI

server_url = 'http://localhost:8080'
token = 'YOUR_TOKEN'
ea = ETAPI(server_url, token)
```

If you haven't created ETAPI token, you can create one with your password. Please note, you can only see this token
once, please save it if you want to reuse the token.

```python
from trilium_py.client import ETAPI

server_url = 'http://localhost:8080'
password = '1234'
ea = ETAPI(server_url)
token = ea.login(password)
print(token)
```

After initialization, you can use Trilium ETAPI with python now. The following are some examples.

### ๐Ÿ“Š Application Information

To start with, you can get the application information like this.

```python
print(ea.app_info())
```

It should give you the version of your server application and some extra information.

### ๐Ÿ” Search note

Search note with keyword.

```python
res = ea.search_note(
    search="python",
)

for x in res['results']:
    print(x['noteId'], x['title'])
```

Search with regular expression. For example, search and get all child notes under certain note:

```python
res = ea.search_note(
    # regular expression search for note title
    search="note.title %= '.*'",
    ancestorNoteId="Parent Note ID",
    fastSearch=False,
    limit=1000,
)
```

### ๐Ÿญ Create Note

You can create a simple note like this.

```python
res = ea.create_note(
    parentNoteId="root",
    title="Simple note 1",
    type="text",
    content="Simple note example",
    noteId="note1"
)
```

The `noteId` is not mandatory, if not provided, Trilium will generate a random one. You can retrieve it in the return.

```python
noteId = res['note']['noteId']
```

#### ๐Ÿ–ผ๏ธ Create Image note

Image note is a special kind of note. You can create an image note with minimal information like this. The `image_file`
refers to the path of image.

```python
res = ea.create_image_note(
    parentNoteId="root",
    title="Image note 1",
    image_file="shield.png",
)
```

### ๐Ÿ‘€ Get note

To retrieve the note's content.

```python
ea.get_note_content("noteid")
```

You can get a note metadata by its id.

```python
ea.get_note(note_id)
```

### ๐Ÿ”„ Update note

Update note content

```python
ea.update_note_content("noteid", "updated by python")
```

Modify note title

```python
ea.patch_note(
    noteId="noteid",
    title="Python client moded",
)
```

### ๐Ÿ—‘๏ธ Delete note

Simply delete a note by id.

```python
ea.delete_note("noteid")
```

### ๐Ÿ“… Day note

You can get the content of a certain date with `get_day_note`. The date string should be in format of "%Y-%m-%d", e.g. "
2022-02-25".

```python
ea.get_day_note("2022-02-25")
```

Then set/update a day note with `set_day_note`. The content should be a (html) string.

```python
ea.set_day_note(date, new_content)
```

### ๐Ÿ“ค Export note

Export note comes in two formats `html` or `markdown`/`md`.

```python
res = ea.export_note(
    noteId='sK5fn4T6yZRI',
    format='md',
    save_path='/home/nate/data/1/test.zip',
)
```

### ๐Ÿ“ฅ import note

This is the built-in feature in trilium. The input file should be a zip file.

```python
res = ea.export_note(
    noteId='sK5fn4T6yZRI',
    file_path='/home/nate/data/1/test.zip',
)
```

### ๐Ÿ’พ Save revision

Save note revision manually.

```
res = ea.save_revision(
    noteId='MJzyFRXAVaC9',
)
```

### ๐Ÿ’พ Create data backup

This example will create a database backup file like this `trilium-data/backup/backup-test.db`.

```python
res = ea.backup("test")
```

You can use the cron utility in Linux to schedule regular automatic backups. For example, to set up a daily backup at 3:
00 AM, you would use the following cron expression:

```bash
0 3 * * * python /path/to/backup-script.py
```

### ๐Ÿท Create attribute

You can create a tag for a note

```python
res = ea.create_attribute(
    noteId='noteid',
    type='label',
    name='name_of_the_tag',
    value='value_of_the_tag',
    isInheritable=True
)
```

The `noteId` is not mandatory, if not provided, Trilium will generate a random one. You can retrieve it in the return.

```python
noteId = res['note']['noteId']
```

### Get attachment list

Get all attachments of a single note.

```
res = ea.get_attachments('uMJt0Ajr1CuC')
```

### Get attachment info

Get image title and etc.

```python
res = ea.get_attachment('Y5V6pYq6nwXo')
```

### Update attachment info

Change image title and etc.

```python
res = ea.update_attachment(
    attachmentId='2b7pPzqocS1s', title='hello etapi', role='image', mime='image/png'
)
```

### Get attachment content

Get the real image file

```python
res = ea.get_attachment_content('icpDE4orQxlI')
with open('1.png', 'wb') as f:
    f.write(res)
```

### Update attachment content

Replace the image with new one

```python
res = ea.update_attachment_content('icWqV6zFtE0V', '/home/nate/data/1.png')
```

### Create attachment

Upload a image file as attachment of a note.

```python
res = ea.create_attachment(
    ownerId='8m8luXym5LxT',
    file_path='/home/nate/data/ksnip_20230630-103509.png',
)
```

## (Advanced Usage) โœ… TODO List

With the power of Python, I have expanded the basic usage of ETAPI. You can do something with todo list now.

### Add TODO item

You can use `add_todo` to add a TODO item, param is the TODO description

```python
ea.add_todo("ไนฐๆš–ๅฎๅฎ")
```

### Check/Uncheck a TODO item

param is the index of the TODO item

```python
ea.todo_check(0)
ea.todo_uncheck(1)
```

### Update a TODO item

Use `update_todo` to update a TODO item description at certain index.

```python
ea.update_todo(0, "ๅŽป็ ๅคดๆ•ด็‚น่–ฏๆก")
```

### Delete a TODO item

Remove a TODO item by its index.

```python
ea.delete_todo(1)
```

### Move yesterday's unfinished todo to today

As the title suggests, you can move yesterday's unfinished things to today. Unfinished todo's will be deleted from
yesterday's note.

```python
ea.move_yesterday_unfinished_todo_to_today()
```

## (Advanced Usage) ๐Ÿšš Upload Markdown files

### Upload single Markdown file with images

You can import Markdown file with images into Trilium now! Trilium-py will help you to upload the images and fix the
links for you!

```python
res = ea.upload_md_file(
    parentNoteId="root",
    file="./md-demo/manjaro ไฟฎๆ”นcaps lock.md",
)
```

### Bulk upload Markdown files in a folder

You can upload a folder with lots of Markdown files to Trilium and preserve the folder structure!

#### Import from VNote

Say, upload all the notes from [VNote](https://github.com/vnotex/vnote), simply do this:

```python
res = ea.upload_md_folder(
    parentNoteId="root",
    mdFolder="~/data/vnotebook/",
    ignoreFolder=['vx_notebook', 'vx_recycle_bin', 'vx_images', '_v_images'],
)
```

#### Import from Joplin

Joplin can be imported effortlessly.

```python
res = ea.upload_md_folder(
    parentNoteId="root",
    mdFolder="/home/nate/data/joplin_data/",
    ignoreFolder=['_resources', ],
)
```

#### Import from Logseq

```python
res = ea.upload_md_folder(
    parentNoteId="root",
    mdFolder="/home/nate/data/logseq_data/",
    ignoreFolder=['assets', 'logseq'],
)
```

#### Import from Obsidian

Obsidian has a very unique linking system for files. You should use [obsidian-export
](https://github.com/zoni/obsidian-export) to convert a Obsidian vault to regular Markdown files. Then you should be
able to import the note into Trilium with trilium-py.

Convert it first.

```bash
obsidian-export /path/to/your/vault /out
```

Then import just like a normal markdown, trilium-py will handle the images for you.

```python
res = ea.upload_md_folder(
    parentNoteId="root",
    mdFolder="E:/data/out",
)
```

#### Import from Youdao Note/ๆœ‰้“ไบ‘็ฌ”่ฎฐ

Youdao does not provide an export feature anymore. Luckily, you can use <https://github.com/DeppWang/youdaonote-pull> to
download your notes and convert them into markdown files. After that, trilium-py should be able to help you import them.

```python
res = ea.upload_md_folder(
    parentNoteId="root",
    mdFolder="/home/nate/gitRepo/youdaonote-pull/out/",
)
```

#### Import from Turtl

You need to convert Turtl from json to markdown first.
See [turtl-to-markdown](https://github.com/Nriver/trilium-py/tree/main/examples/turtl-to-markdown) for details.

Then you can import with trilium-py like this:

```python
res = ea.upload_md_folder(
    parentNoteId="root",
    mdFolder="/home/nate/gitRepo/turtl-to-markdown/out/",
    ignoreFolder=['_resources'],
)
```

#### Import from other markdown software

In general, markdown files have variety of standards. You can always try import them with

```python
res = ea.upload_md_folder(
    parentNoteId="root",
    mdFolder="/home/nate/data/your_markdown_files/",
)
```

If there is any problem, please feel free to create an [issue](https://github.com/Nriver/trilium-py/issues/new).

## (Advanced Usage) ๐ŸŽจ Beautify notes

Because of the constraints imposed by the library utilized by Trilium, imported notes may experience minor formatting
problems. These issues include an additional line appearing at the end of code blocks, images becoming integrated with
the note content, and the absence of line breaks between headings, resulting in a cramped appearance of the note
content.

Here is what you can do to beautify your note.

### Beautify a note

Specify a note id to beautify note content.

```python
ea.beautify_note('krm8B9JthNfi')
```

### Beautify a note and its child notes

```python
ea.beautify_sub_notes('tlPuzU2szLJh')
```

## (Advanced Usage) ๐Ÿงน Sort note content

Sort a note by the heading names. This feature could prove invaluable for notes containing extensive lists, such as book
titles sorted into various genres. It's equally useful for managing browser bookmarks or collecting links.

Additionally, you have the option to specify a language code for sorting based on your local language. This enhances the
sorting process and tailors it to your linguistic preferences.

```python
res = ea.sort_note_content('lPxtkknjR2bJ')
res = ea.sort_note_content('y6hROhWjNmHQ', 'zh_CN.UTF-8')
```

## (Advanced Usage) ๐Ÿงน Delete empty `new note`

Sometimes I inadvertently create numerous "new notes" which remain undeleted within my note tree. These "new notes" clutter my
workspace, scattered across various locations. I made this bulk deletion of these empty "new notes." Additionally, it
generates warning messages for "new notes" that contain content, maybe we should change the title for those notes.

```python
ea.delete_empty_note()
```

## (Advanced Usage) ๐Ÿ—œ๏ธ Optimize image size

Try to reduce image size by using PIL's optimize feature. If the image in your note is not compressed, you can try this.
I've successfully convert a note of 44MB to 9.9MB after this process. Backup your data before try this.

The default quality is set to 90.

`optimize_image_attachments` will keep the original image format and try to compress it.

```
ea.optimize_image_attachments('uMJt0Ajr1CuC')
```

To save even more space, you can try the following method.

The `optimize_image_attachments_to_webp` function converts images to the `WebP` format, significantly reducing file
sizes. Based on my experience, `WebP` images can be as little as 25% to 50% of the size of `PNG` images.

```
ea.optimize_image_attachments_to_webp('H2q3901uFDCH')
```

This action can save significant space if you have many clipped pages. Whoever invented `WebP` is a genius.

## ๐Ÿ› ๏ธ Develop

Install with pip egg link to make package change without reinstall.

```python
python -m pip install --user -e .
```

## ๐Ÿ”— Original OpenAPI Documentation

The original OpenAPI document is [here](https://github.com/zadam/trilium/blob/master/src/etapi/etapi.openapi.yaml). You
can open it with [swagger editor](https://editor.swagger.io/).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nriver/trilium-py",
    "name": "trilium-py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.9",
    "maintainer_email": null,
    "keywords": "trilium, etapi, api client",
    "author": "Nriver",
    "author_email": null,
    "download_url": null,
    "platform": null,
    "description": "# \ud83d\udc0d trilium-py\n\n<p align=\"center\">\nEnglish | <a href=\"README_CN.md\">\u7b80\u4f53\u4e2d\u6587</a>\n</p>\n\nPython client for ETAPI of Trilium Note.\n\n[![Downloads](https://static.pepy.tech/badge/trilium-py)](https://pepy.tech/project/trilium-py)\n[![Supported Versions](https://img.shields.io/pypi/pyversions/trilium-py.svg)](https://pypi.org/project/trilium-py)\n[![Supported Versions](https://img.shields.io/pypi/v/trilium-py?color=%2334D058&label=pypi%20package)](https://pypi.org/project/trilium-py)\n[![PyPI license](https://img.shields.io/pypi/l/trilium-py.svg)](https://pypi.python.org/pypi/trilium-py/)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)\n\n## \ud83e\uddae Table of Contents\n\n<!--ts-->\n\n* [\ud83d\udc0d trilium-py](#-trilium-py)\n    * [\ud83e\uddae Table of Contents](#-table-of-contents)\n    * [\ud83d\udd27 Installation](#-installation)\n    * [\ud83d\udcd6 (Basic) Usage](#-basic-usage)\n        * [\ud83d\ude80 Initialization](#-initialization)\n        * [\ud83d\udcca Application Information](#-application-information)\n        * [\ud83d\udd0d Search note](#-search-note)\n        * [\ud83c\udfed Create Note](#-create-note)\n            * [\ud83d\uddbc\ufe0f Create Image note](#\ufe0f-create-image-note)\n        * [\ud83d\udc40 Get note](#-get-note)\n        * [\ud83d\udd04 Update note](#-update-note)\n        * [\ud83d\uddd1\ufe0f Delete note](#\ufe0f-delete-note)\n        * [\ud83d\udcc5 Day note](#-day-note)\n        * [\ud83d\udce4 Export note](#-export-note)\n        * [\ud83d\udce5 import note](#-import-note)\n        * [\ud83d\udcbe Save revision](#-save-revision)\n        * [\ud83d\udcbe Create data backup](#-create-data-backup)\n        * [\ud83c\udff7 Create attribute](#-create-attribute)\n        * [Get attachment list](#get-attachment-list)\n        * [Get attachment info](#get-attachment-info)\n        * [Update attachment info](#update-attachment-info)\n        * [Get attachment content](#get-attachment-content)\n        * [Update attachment content](#update-attachment-content)\n        * [Create attachment](#create-attachment)\n    * [(Advanced Usage) \u2705 TODO List](#advanced-usage--todo-list)\n        * [Add TODO item](#add-todo-item)\n        * [Check/Uncheck a TODO item](#checkuncheck-a-todo-item)\n        * [Update a TODO item](#update-a-todo-item)\n        * [Delete a TODO item](#delete-a-todo-item)\n        * [Move yesterday's unfinished todo to today](#move-yesterdays-unfinished-todo-to-today)\n    * [(Advanced Usage) \ud83d\ude9a Upload Markdown files](#advanced-usage--upload-markdown-files)\n        * [Upload single Markdown file with images](#upload-single-markdown-file-with-images)\n        * [Bulk upload Markdown files in a folder](#bulk-upload-markdown-files-in-a-folder)\n            * [Import from VNote](#import-from-vnote)\n            * [Import from Joplin](#import-from-joplin)\n            * [Import from Logseq](#import-from-logseq)\n            * [Import from Obsidian](#import-from-obsidian)\n            * [Import from Youdao Note/\u6709\u9053\u4e91\u7b14\u8bb0](#import-from-youdao-note\u6709\u9053\u4e91\u7b14\u8bb0)\n            * [Import from Turtl](#import-from-turtl)\n            * [Import from other markdown software](#import-from-other-markdown-software)\n    * [(Advanced Usage) \ud83c\udfa8 Beautify notes](#advanced-usage--beautify-notes)\n        * [Beautify a note](#beautify-a-note)\n        * [Beautify a note and its child notes](#beautify-a-note-and-its-child-notes)\n    * [(Advanced Usage) \ud83e\uddf9 Sort note content](#advanced-usage--sort-note-content)\n    * [(Advanced Usage) \ud83e\uddf9 Delete empty new note](#advanced-usage--delete-empty-new-note)\n    * [(Advanced Usage) \ud83d\udddc\ufe0f Optimize image size](#advanced-usage-\ufe0f-optimize-image-size)\n    * [\ud83d\udee0\ufe0f Develop](#\ufe0f-develop)\n    * [\ud83d\udd17 Original OpenAPI Documentation](#-original-openapi-documentation)\n\n<!--te-->\n\n## \ud83d\udd27 Installation\n\n```bash\npython3 -m pip install trilium-py --user\n```\n\n## \ud83d\udcd6 (Basic) Usage\n\nThese are basic function that Trilium's ETAPI provides. Down below are some simple example code to use this package.\n\n### \ud83d\ude80 Initialization\n\nIf you have a ETAPI token, change the `server_url` and `token` to yours.\n\n```python\nfrom trilium_py.client import ETAPI\n\nserver_url = 'http://localhost:8080'\ntoken = 'YOUR_TOKEN'\nea = ETAPI(server_url, token)\n```\n\nIf you haven't created ETAPI token, you can create one with your password. Please note, you can only see this token\nonce, please save it if you want to reuse the token.\n\n```python\nfrom trilium_py.client import ETAPI\n\nserver_url = 'http://localhost:8080'\npassword = '1234'\nea = ETAPI(server_url)\ntoken = ea.login(password)\nprint(token)\n```\n\nAfter initialization, you can use Trilium ETAPI with python now. The following are some examples.\n\n### \ud83d\udcca Application Information\n\nTo start with, you can get the application information like this.\n\n```python\nprint(ea.app_info())\n```\n\nIt should give you the version of your server application and some extra information.\n\n### \ud83d\udd0d Search note\n\nSearch note with keyword.\n\n```python\nres = ea.search_note(\n    search=\"python\",\n)\n\nfor x in res['results']:\n    print(x['noteId'], x['title'])\n```\n\nSearch with regular expression. For example, search and get all child notes under certain note:\n\n```python\nres = ea.search_note(\n    # regular expression search for note title\n    search=\"note.title %= '.*'\",\n    ancestorNoteId=\"Parent Note ID\",\n    fastSearch=False,\n    limit=1000,\n)\n```\n\n### \ud83c\udfed Create Note\n\nYou can create a simple note like this.\n\n```python\nres = ea.create_note(\n    parentNoteId=\"root\",\n    title=\"Simple note 1\",\n    type=\"text\",\n    content=\"Simple note example\",\n    noteId=\"note1\"\n)\n```\n\nThe `noteId` is not mandatory, if not provided, Trilium will generate a random one. You can retrieve it in the return.\n\n```python\nnoteId = res['note']['noteId']\n```\n\n#### \ud83d\uddbc\ufe0f Create Image note\n\nImage note is a special kind of note. You can create an image note with minimal information like this. The `image_file`\nrefers to the path of image.\n\n```python\nres = ea.create_image_note(\n    parentNoteId=\"root\",\n    title=\"Image note 1\",\n    image_file=\"shield.png\",\n)\n```\n\n### \ud83d\udc40 Get note\n\nTo retrieve the note's content.\n\n```python\nea.get_note_content(\"noteid\")\n```\n\nYou can get a note metadata by its id.\n\n```python\nea.get_note(note_id)\n```\n\n### \ud83d\udd04 Update note\n\nUpdate note content\n\n```python\nea.update_note_content(\"noteid\", \"updated by python\")\n```\n\nModify note title\n\n```python\nea.patch_note(\n    noteId=\"noteid\",\n    title=\"Python client moded\",\n)\n```\n\n### \ud83d\uddd1\ufe0f Delete note\n\nSimply delete a note by id.\n\n```python\nea.delete_note(\"noteid\")\n```\n\n### \ud83d\udcc5 Day note\n\nYou can get the content of a certain date with `get_day_note`. The date string should be in format of \"%Y-%m-%d\", e.g. \"\n2022-02-25\".\n\n```python\nea.get_day_note(\"2022-02-25\")\n```\n\nThen set/update a day note with `set_day_note`. The content should be a (html) string.\n\n```python\nea.set_day_note(date, new_content)\n```\n\n### \ud83d\udce4 Export note\n\nExport note comes in two formats `html` or `markdown`/`md`.\n\n```python\nres = ea.export_note(\n    noteId='sK5fn4T6yZRI',\n    format='md',\n    save_path='/home/nate/data/1/test.zip',\n)\n```\n\n### \ud83d\udce5 import note\n\nThis is the built-in feature in trilium. The input file should be a zip file.\n\n```python\nres = ea.export_note(\n    noteId='sK5fn4T6yZRI',\n    file_path='/home/nate/data/1/test.zip',\n)\n```\n\n### \ud83d\udcbe Save revision\n\nSave note revision manually.\n\n```\nres = ea.save_revision(\n    noteId='MJzyFRXAVaC9',\n)\n```\n\n### \ud83d\udcbe Create data backup\n\nThis example will create a database backup file like this `trilium-data/backup/backup-test.db`.\n\n```python\nres = ea.backup(\"test\")\n```\n\nYou can use the cron utility in Linux to schedule regular automatic backups. For example, to set up a daily backup at 3:\n00 AM, you would use the following cron expression:\n\n```bash\n0 3 * * * python /path/to/backup-script.py\n```\n\n### \ud83c\udff7 Create attribute\n\nYou can create a tag for a note\n\n```python\nres = ea.create_attribute(\n    noteId='noteid',\n    type='label',\n    name='name_of_the_tag',\n    value='value_of_the_tag',\n    isInheritable=True\n)\n```\n\nThe `noteId` is not mandatory, if not provided, Trilium will generate a random one. You can retrieve it in the return.\n\n```python\nnoteId = res['note']['noteId']\n```\n\n### Get attachment list\n\nGet all attachments of a single note.\n\n```\nres = ea.get_attachments('uMJt0Ajr1CuC')\n```\n\n### Get attachment info\n\nGet image title and etc.\n\n```python\nres = ea.get_attachment('Y5V6pYq6nwXo')\n```\n\n### Update attachment info\n\nChange image title and etc.\n\n```python\nres = ea.update_attachment(\n    attachmentId='2b7pPzqocS1s', title='hello etapi', role='image', mime='image/png'\n)\n```\n\n### Get attachment content\n\nGet the real image file\n\n```python\nres = ea.get_attachment_content('icpDE4orQxlI')\nwith open('1.png', 'wb') as f:\n    f.write(res)\n```\n\n### Update attachment content\n\nReplace the image with new one\n\n```python\nres = ea.update_attachment_content('icWqV6zFtE0V', '/home/nate/data/1.png')\n```\n\n### Create attachment\n\nUpload a image file as attachment of a note.\n\n```python\nres = ea.create_attachment(\n    ownerId='8m8luXym5LxT',\n    file_path='/home/nate/data/ksnip_20230630-103509.png',\n)\n```\n\n## (Advanced Usage) \u2705 TODO List\n\nWith the power of Python, I have expanded the basic usage of ETAPI. You can do something with todo list now.\n\n### Add TODO item\n\nYou can use `add_todo` to add a TODO item, param is the TODO description\n\n```python\nea.add_todo(\"\u4e70\u6696\u5b9d\u5b9d\")\n```\n\n### Check/Uncheck a TODO item\n\nparam is the index of the TODO item\n\n```python\nea.todo_check(0)\nea.todo_uncheck(1)\n```\n\n### Update a TODO item\n\nUse `update_todo` to update a TODO item description at certain index.\n\n```python\nea.update_todo(0, \"\u53bb\u7801\u5934\u6574\u70b9\u85af\u6761\")\n```\n\n### Delete a TODO item\n\nRemove a TODO item by its index.\n\n```python\nea.delete_todo(1)\n```\n\n### Move yesterday's unfinished todo to today\n\nAs the title suggests, you can move yesterday's unfinished things to today. Unfinished todo's will be deleted from\nyesterday's note.\n\n```python\nea.move_yesterday_unfinished_todo_to_today()\n```\n\n## (Advanced Usage) \ud83d\ude9a Upload Markdown files\n\n### Upload single Markdown file with images\n\nYou can import Markdown file with images into Trilium now! Trilium-py will help you to upload the images and fix the\nlinks for you!\n\n```python\nres = ea.upload_md_file(\n    parentNoteId=\"root\",\n    file=\"./md-demo/manjaro \u4fee\u6539caps lock.md\",\n)\n```\n\n### Bulk upload Markdown files in a folder\n\nYou can upload a folder with lots of Markdown files to Trilium and preserve the folder structure!\n\n#### Import from VNote\n\nSay, upload all the notes from [VNote](https://github.com/vnotex/vnote), simply do this:\n\n```python\nres = ea.upload_md_folder(\n    parentNoteId=\"root\",\n    mdFolder=\"~/data/vnotebook/\",\n    ignoreFolder=['vx_notebook', 'vx_recycle_bin', 'vx_images', '_v_images'],\n)\n```\n\n#### Import from Joplin\n\nJoplin can be imported effortlessly.\n\n```python\nres = ea.upload_md_folder(\n    parentNoteId=\"root\",\n    mdFolder=\"/home/nate/data/joplin_data/\",\n    ignoreFolder=['_resources', ],\n)\n```\n\n#### Import from Logseq\n\n```python\nres = ea.upload_md_folder(\n    parentNoteId=\"root\",\n    mdFolder=\"/home/nate/data/logseq_data/\",\n    ignoreFolder=['assets', 'logseq'],\n)\n```\n\n#### Import from Obsidian\n\nObsidian has a very unique linking system for files. You should use [obsidian-export\n](https://github.com/zoni/obsidian-export) to convert a Obsidian vault to regular Markdown files. Then you should be\nable to import the note into Trilium with trilium-py.\n\nConvert it first.\n\n```bash\nobsidian-export /path/to/your/vault /out\n```\n\nThen import just like a normal markdown, trilium-py will handle the images for you.\n\n```python\nres = ea.upload_md_folder(\n    parentNoteId=\"root\",\n    mdFolder=\"E:/data/out\",\n)\n```\n\n#### Import from Youdao Note/\u6709\u9053\u4e91\u7b14\u8bb0\n\nYoudao does not provide an export feature anymore. Luckily, you can use <https://github.com/DeppWang/youdaonote-pull> to\ndownload your notes and convert them into markdown files. After that, trilium-py should be able to help you import them.\n\n```python\nres = ea.upload_md_folder(\n    parentNoteId=\"root\",\n    mdFolder=\"/home/nate/gitRepo/youdaonote-pull/out/\",\n)\n```\n\n#### Import from Turtl\n\nYou need to convert Turtl from json to markdown first.\nSee [turtl-to-markdown](https://github.com/Nriver/trilium-py/tree/main/examples/turtl-to-markdown) for details.\n\nThen you can import with trilium-py like this:\n\n```python\nres = ea.upload_md_folder(\n    parentNoteId=\"root\",\n    mdFolder=\"/home/nate/gitRepo/turtl-to-markdown/out/\",\n    ignoreFolder=['_resources'],\n)\n```\n\n#### Import from other markdown software\n\nIn general, markdown files have variety of standards. You can always try import them with\n\n```python\nres = ea.upload_md_folder(\n    parentNoteId=\"root\",\n    mdFolder=\"/home/nate/data/your_markdown_files/\",\n)\n```\n\nIf there is any problem, please feel free to create an [issue](https://github.com/Nriver/trilium-py/issues/new).\n\n## (Advanced Usage) \ud83c\udfa8 Beautify notes\n\nBecause of the constraints imposed by the library utilized by Trilium, imported notes may experience minor formatting\nproblems. These issues include an additional line appearing at the end of code blocks, images becoming integrated with\nthe note content, and the absence of line breaks between headings, resulting in a cramped appearance of the note\ncontent.\n\nHere is what you can do to beautify your note.\n\n### Beautify a note\n\nSpecify a note id to beautify note content.\n\n```python\nea.beautify_note('krm8B9JthNfi')\n```\n\n### Beautify a note and its child notes\n\n```python\nea.beautify_sub_notes('tlPuzU2szLJh')\n```\n\n## (Advanced Usage) \ud83e\uddf9 Sort note content\n\nSort a note by the heading names. This feature could prove invaluable for notes containing extensive lists, such as book\ntitles sorted into various genres. It's equally useful for managing browser bookmarks or collecting links.\n\nAdditionally, you have the option to specify a language code for sorting based on your local language. This enhances the\nsorting process and tailors it to your linguistic preferences.\n\n```python\nres = ea.sort_note_content('lPxtkknjR2bJ')\nres = ea.sort_note_content('y6hROhWjNmHQ', 'zh_CN.UTF-8')\n```\n\n## (Advanced Usage) \ud83e\uddf9 Delete empty `new note`\n\nSometimes I inadvertently create numerous \"new notes\" which remain undeleted within my note tree. These \"new notes\" clutter my\nworkspace, scattered across various locations. I made this bulk deletion of these empty \"new notes.\" Additionally, it\ngenerates warning messages for \"new notes\" that contain content, maybe we should change the title for those notes.\n\n```python\nea.delete_empty_note()\n```\n\n## (Advanced Usage) \ud83d\udddc\ufe0f Optimize image size\n\nTry to reduce image size by using PIL's optimize feature. If the image in your note is not compressed, you can try this.\nI've successfully convert a note of 44MB to 9.9MB after this process. Backup your data before try this.\n\nThe default quality is set to 90.\n\n`optimize_image_attachments` will keep the original image format and try to compress it.\n\n```\nea.optimize_image_attachments('uMJt0Ajr1CuC')\n```\n\nTo save even more space, you can try the following method.\n\nThe `optimize_image_attachments_to_webp` function converts images to the `WebP` format, significantly reducing file\nsizes. Based on my experience, `WebP` images can be as little as 25% to 50% of the size of `PNG` images.\n\n```\nea.optimize_image_attachments_to_webp('H2q3901uFDCH')\n```\n\nThis action can save significant space if you have many clipped pages. Whoever invented `WebP` is a genius.\n\n## \ud83d\udee0\ufe0f Develop\n\nInstall with pip egg link to make package change without reinstall.\n\n```python\npython -m pip install --user -e .\n```\n\n## \ud83d\udd17 Original OpenAPI Documentation\n\nThe original OpenAPI document is [here](https://github.com/zadam/trilium/blob/master/src/etapi/etapi.openapi.yaml). You\ncan open it with [swagger editor](https://editor.swagger.io/).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python client for ETAPI of Trilium Note. With some extra features powered by Python :)",
    "version": "0.9.6",
    "project_urls": {
        "Bug Reports": "https://github.com/nriver/trilium-py/issues",
        "Funding": "https://github.com/nriver/trilium-py",
        "Homepage": "https://github.com/nriver/trilium-py",
        "Say Thanks!": "https://github.com/nriver/trilium-py",
        "Source": "https://github.com/nriver/trilium-py/"
    },
    "split_keywords": [
        "trilium",
        " etapi",
        " api client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cbf27d92b39f26b948e0792ab8c1581f03ab237abe2f156caa6dbcfe3a442c00",
                "md5": "e7448519b427e0071ab400f7c9d32eb9",
                "sha256": "f641e32b86c37510a64ef6df1eb548a293e4a7ee7d1f38f9334d15d5ffebe367"
            },
            "downloads": -1,
            "filename": "trilium_py-0.9.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e7448519b427e0071ab400f7c9d32eb9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.9",
            "size": 36789,
            "upload_time": "2024-06-11T02:03:52",
            "upload_time_iso_8601": "2024-06-11T02:03:52.057579Z",
            "url": "https://files.pythonhosted.org/packages/cb/f2/7d92b39f26b948e0792ab8c1581f03ab237abe2f156caa6dbcfe3a442c00/trilium_py-0.9.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-11 02:03:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nriver",
    "github_project": "trilium-py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "BeautifulSoup4",
            "specs": []
        },
        {
            "name": "python-magic",
            "specs": []
        },
        {
            "name": "python-magic",
            "specs": []
        },
        {
            "name": "python-magic-bin",
            "specs": []
        },
        {
            "name": "markdown2",
            "specs": []
        },
        {
            "name": "natsort",
            "specs": []
        },
        {
            "name": "loguru",
            "specs": []
        },
        {
            "name": "minify-html",
            "specs": []
        },
        {
            "name": "pillow",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "trilium-py"
}
        
Elapsed time: 0.26614s