trilium_alchemy.core.session¶
Implementation of session functionality.
Class index¶
Canonical
Interface to Trilium and context in which to store changes to entities. |
Symbols¶
- class trilium_alchemy.core.session.Session(host: str, token: str | None = None, *, password: str | None = None, default: bool = True, logger: logging.Logger | None = None)¶
Initialization:
Either
tokenorpasswordis required; if both are provided,tokentakes precedence.- Parameters:
- host
Hostname of Trilium server
- token
ETAPI token
- password
Trilium password, if no token provided
- default
Register this as the default session; in this case,
sessionmay be omitted from entity constructors- logger
Logger to use, or
Noneto use default logger
Bases:
alchemizer.BaseSessionAliases:
trilium_alchemy.Session
trilium_alchemy.core.SessionInterface to Trilium and context in which to store changes to entities.
Changes to entities are tracked as they’re made by the user. The user must then invoke
Session.flushto commit them.For details and example usage, see Sessions in the user guide.
- property dirty_set: set[BaseEntity]¶
Copy of all dirty
BaseEntityobjects.
- property dirty_map: dict[alchemizer.State, set[BaseEntity]]¶
Mapping of state to dirty
BaseEntityobjects in that state.Example usage:
create_entities = my_session.dirty_map[State.CREATE]
- property api: trilium_client.api.default_api.DefaultApi¶
ETAPI client object.
Used internally and exposed for manual low-level operations. For its documentation, see: https://github.com/mm21/trilium-client
- flush(entities: Iterable[BaseEntity] | None = None)¶
Commits pending changes to Trilium via ETAPI.
If
entitiespassed, only flushes those entities and their dependencies.If
entities = None, flushes all dirty entities.Note
You may equivalently invoke
Entity.flushto flush aBaseEntityalong with its dependencies.- Parameters:
- entities
Entities for which to commit changes, internally processed as a
setand sorted according to dependencies
- search(query: str, order_by: str | None = None, order_direction: Literal[asc, desc] | None = None, limit: int | None = None, fast_search: bool = False, include_archived_notes: bool = False, ancestor_note: Note | None = None, ancestor_depth: int | None = None, debug: bool = False) list[Note]¶
Perform note search using query string as described at: https://docs.triliumnotes.org/user-guide/concepts/navigation/search
- Parameters:
- query
Query string
- order_by
Name of the property/label to order search results by
- order_direction
Ascending (
"asc") or descending ("desc"), ascending by default- limit
Limit the number of results to receive
- fast_search
Enable fast search (doesn’t search content)
- include_archived_notes
Include archived notes
- ancestor_note
Search only in subtree of provided note
- ancestor_depth
Define how deep in the tree should the notes be searched
- debug
Get debug information in the response (search query parsing)
- Returns:
List of notes
- backup(name: str)¶
Create backup with provided name, e.g.
nowwill writebackup-now.db.- Parameters:
- name
Name of backup to write
- get_day_note(date: datetime.date) Note¶
Returns a day note for a given date.
Gets created if doesn’t exist.
- Parameters:
- date
Date object, e.g.
datetime.date(2023, 7, 5)
- get_week_note(week: str) Note¶
Returns a week note for a given date.
Gets created if doesn’t exist.
- Parameters:
- date
Week as ISO 8601 week identifier
YYYY-Www, e.g.2023-W10
- get_month_note(month: str) Note¶
Returns a month note for a given date.
Gets created if doesn’t exist.
- Parameters:
- month
Month in the form
yyyy-mm, e.g.2023-07
- get_year_note(year: str) Note¶
Returns a year note for a given date.
Gets created if doesn’t exist.
- Parameters:
- year
Year as string
- get_inbox_note(date: datetime.date) Note¶
Returns an “inbox” note into which note can be created.
Date will be used depending on whether the inbox is a fixed note (identified with
#inboxlabel) or a day note in a journal.- Parameters:
- date
Date object, e.g.
datetime.date(2023, 7, 5)
- get_app_info() trilium_client.models.app_info.AppInfo¶
Returns app info.
See https://github.com/mm21/trilium-client/blob/main/docs/AppInfo.md for its definition.
- refresh_note_ordering(note: Note)¶
Refresh ordering of provided note’s children for any connected clients.
Note
This API is automatically invoked after any child branch positions are adjusted. It should rarely be required, but is provided for completeness.
- classmethod login(host: str, password: str) str¶
Login using a password and get an ETAPI token.
Note
You can implicitly login by passing
passwordwhen creating aSession. This API should rarely be required, but is provided for completeness.- Parameters:
- host
Hostname of Trilium server
- password
Trilium password
- Returns:
ETAPI token
- logout()¶
Deletes the currently active API token, if this
Sessionwas created with apasswordrather thantoken.Warning
Subsequent attempts to invoke ETAPI methods using this
Session, such as those invoked byflush, will fail.If this
Sessionwas instead created with a token, a warning will be generated and no action will be taken. For token-based sessions there’s no corresponding login.
- deregister_default()¶
If this session was registered as default, deregister it.
No-op otherwise.