Skip to main content

"Joplin Editor - API"

Project description

Joplin Api

Joplin API

The API of Joplin Editor in Python 3.7+

requirements

Installation

git clone  https://github.com/foxmask/joplin-api
cd joplin-api
pip install -e .

Using Joplin API

Have a look at tests/test_folder.py and test/test_ping.py

async

basically

import asyncio
from joplin_api import JoplinApi
joplin = JoplinApi(token='my token')

async def ping_me():
    await joplin.ping()

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(ping_me())
finally:
    loop.close()

create a folder

import asyncio
from joplin_api import JoplinApi
joplin = JoplinApi(token='my token')

async def new_folder():
    folder = 'TEST FOLDER1'
    res = await joplin.create_folder(folder=folder)

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(new_folder())
finally:
    loop.close()

create a note

import asyncio
from joplin_api import JoplinApi
joplin = JoplinApi(token='my token')

async def new_note(get_token):
    # 1 - create a folder
    res = await joplin.create_folder(folder='MY FOLDER')
    data = res.json()
    parent_id = data['id']
    # 2 - create a note with tag
    body = '# title 1\n ## subtitle \n ```python\npython --version\n```'
    assert type(body) is str
    kwargs = {'tags': 'tag1, tag2'}
    await joplin.create_note(title="MY NOTE", body=body,
                             parent_id=parent_id, **kwargs)

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(new_note())
finally:
    loop.close()

sync

basically

from joplin_api import JoplinApiSync
joplin = JoplinApiSync(token='my token')

def ping_me():
    joplin.ping()

create a folder

from joplin_api import JoplinApiSync
joplin = JoplinApiSync(token='my token')

def new_folder():
    folder = 'TEST FOLDER1'
    joplin.create_folder(folder=folder)

create a note

import asyncio
from joplin_api import JoplinApiSync
joplin = JoplinApiSync(token='my token')

def new_note(get_token):
    # 1 - create a folder
    res = joplin.create_folder(folder='MY FOLDER')
    data = res.json()
    parent_id = data['id']
    # 2 - create a note with tag
    body = '# title 1\n ## subtitle \n ```python\npython --version\n```'
    assert type(body) is str
    kwargs = {'tags': 'tag1, tag2'}
    joplin.create_note(title="MY NOTE", body=body,
                       parent_id=parent_id, **kwargs)

Logging

By default the API will log in DEBUG mode as it is very verbose. If you want to enable the log then set this environment variable

export JOPLIN_API_LOGLEVEL=DEBUG

Python 3.7

with python 3.7 and asyncio, replace

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(new_note())
finally:
    loop.close()

by

asyncio.run(new_note())

Tests

install pytest by

pip install -r requirements-dev.txt

then, before starting the Unit Test, you will need to set the Token line 10 of tests/conftest.py file

and run

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for joplin-api, version 1.6.0
Filename, size File type Python version Upload date Hashes
Filename, size joplin_api-1.6.0-py3.8.egg (22.9 kB) File type Egg Python version 3.8 Upload date Hashes View
Filename, size joplin_api-1.6.0-py3-none-any.whl (11.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size joplin_api-1.6.0.tar.gz (8.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page