note
This module contains the classes that represent Obsidian notes. It provides classes for reading, writing, and retrieving properties of Obsidian notes.
Note(path: str, content: Optional[str] = None)
Represents a note in Obsidian vault.
Parameters:
-
path
(str
) –The path of the note.
-
content
(str
, default:None
) –The content of the note. If not provided, it will be read from the note file.
Source code in pyobsidian/note.py
360 361 362 363 364 |
|
path: str
property
Retrieves the normalized path of the note.
Returns:
-
str
–The normalized path of the note.
properties: NoteProperties
property
read() -> str
Reads the content of a note from the file.
Returns:
-
str
–The content of the note file
Source code in pyobsidian/note.py
399 400 401 402 403 404 405 406 407 |
|
write() -> str
Writes the content of a note to the file.
Returns:
-
str
–The path of the written note
Source code in pyobsidian/note.py
409 410 411 412 413 414 415 416 417 418 419 |
|
NoteProperties(path: str, content: str)
A class used to retrieve properties of Obsidian notes.
Parameters:
-
path
(str
) –The path of the note file
-
content
(str
) –The content of the note file
Source code in pyobsidian/note.py
26 27 28 |
|
content: str
property
writable
The content of the note file
Returns:
-
str
–The content of the note file
creation_time: datetime
property
Retrieves the creation time of the note file.
Notes
It uses the os.path.getctime
function to retrieve the creation time of the file.
Returns:
-
datetime
–The creation time of the note file.
filename: str
property
Returns the filename of the current object's path.
This property takes the path of the current object and splits it using the operating system's path separator. It then extracts the last element of the resulting list, which represents the filename. The filename is further split using the dot separator to remove the file extension. The function then returns the extracted filename as a string.
Returns:
-
str
–Note filename.
folder: list[str]
property
Retrieves the folders path of the current note as a list of strings. All combinations of the folder path are returned. For example, if the folder path is "C:/Users/user/vault", it returns ['C:', 'C:/Users', 'C:/Users/user', 'C:/Users/user/vault']
Returns:
-
list[str]
–A list containing the folders path of the current note.
last_access_time: datetime
property
Retrieves the last access time of the file.
Notes
It uses the os.path.getatime
function to retrieve the last access time of the file.
Returns:
-
datetime
–The last access time of the file.
last_modification_time: datetime
property
Retrieves the last modification time of the file.
Notes
It uses the os.path.getmtime
function to retrieve the last modification time of the file.
Returns:
-
datetime
–The last modification time of the file.
path: str
property
The path of the note file
Returns:
-
str
–The path of the note file
related_note: dict[str, Optional[list[str]] | Optional[dict[str, list[str]]]]
property
Retrieves related notes from both YAML content and inline content.
This property returns a dictionary containing the related notes extracted from both the YAML content and inline content of the note. The dictionary has two keys: - 'yaml': The related notes extracted from the YAML content of the note. It is a dictionary where the keys are the YAML keys and the values are lists of related note names. - 'inline': The related notes extracted from the inline content of the note. It is a list of related note names.
Returns:
-
dict[str, Union[list[str], dict[str, list[str]]]]
–A dictionary containing the related notes extracted from both the YAML content and inline content of the note.
tag: dict[str, Optional[list[str]]]
property
Retrieves the tags from the note.
This property returns a dictionary containing the tags extracted from the note. The dictionary has two keys:
- 'yaml': The tags extracted from the YAML content of the note. It is a list of strings or None if no tags are found.
- 'inline': The tags extracted from the inline content of the note. It is a list of strings or None if no tags are found.
Returns:
-
dict[str, Optional[list[str]]]
–A dictionary containing the tags extracted from the note.
yaml_content: Optional[dict]
property
Retrieves the YAML content from the note. The YAML is identified by '---'. All text between these two delimiters is considered part of the YAML content. If more than one '---' separator is found, only the first pair is considered.
Notes
See Obsidian properties for more details.
Returns:
-
Optional[dict]
–The YAML content of the note, or None if no YAML content is found.
_get_related_notes_inline() -> Optional[list[str]]
Retrieves all the related notes that are inline in the content of the note.
This function uses regular expressions to find all occurrences of related notes in the content of the note. The related notes are identified by the pattern [[note|alias]], where 'note' is the name of the related note and 'alias' is an optional alias for the note. The function removes the alias from the related note and returns a list of the related notes without aliases.
Returns:
-
Optional[list[str]]
–A list of related notes found in the content, without aliases, or None if no related notes are found.
Source code in pyobsidian/note.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
_get_related_notes_yaml() -> Optional[dict[str, list[str]]]
Retrieves related notes from YAML content.
This function searches for related notes in the YAML content of the note. It uses regular expressions to find all occurrences of related notes in the YAML content. The related notes are identified by the pattern [[note|alias]], where 'note' is the name of the related note and 'alias' is an optional alias for the note. The function removes the alias from the related note and returns a dictionary of the related notes, grouped by the YAML key.
Returns:
-
Optional[dict[str, list[str]]]
–A dictionary of related notes found in the YAML content, grouped by the YAML key, or None if no related notes are found.
Source code in pyobsidian/note.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
_get_tags_inline() -> Optional[list[str]]
Retrieves all the inline tags from the content of the note.
This function uses regular expressions to find all occurrences of tags in the content of the note. The tags are identified by the pattern '#tag', where 'tag' is any non-whitespace sequence of characters.
Returns:
-
Optional[list[str]]
–A list of tags found in the content, or None if no tags are found.
Source code in pyobsidian/note.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
_get_tags_yaml() -> Optional[list[str]]
Retrieves the tags from the YAML content of the note.
Returns:
-
Optional[list[str]]
–The list of tags if they exist in the YAML content, otherwise None.
Source code in pyobsidian/note.py
52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
_get_yaml_field(field: str) -> Optional[str | list[str]]
Retrieves the value of a specified field from the YAML content of the note.
Parameters:
-
field
(str
) –The name of the field to retrieve the value of.
Returns:
-
Optional[str | list[str]]
–The value of the specified field if it exists in the YAML content, otherwise None.
Source code in pyobsidian/note.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|