Bookmarks API¶
The bookmarks module manages bookmarks and folders.
Overview¶
Astronomo stores bookmarks in ~/.config/astronomo/bookmarks.toml. Bookmarks can optionally be organized into folders.
API Reference¶
bookmarks
¶
Bookmarks management for Astronomo.
This module provides bookmark storage with folder organization and TOML persistence.
Bookmark
dataclass
¶
Bookmark(
id: str,
url: str,
title: str,
folder_id: str | None = None,
created_at: datetime = datetime.now(),
)
Represents a single bookmark.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier (UUID) |
url |
str
|
The Gemini URL |
title |
str
|
Display title for the bookmark |
folder_id |
str | None
|
ID of containing folder, or None for root level |
created_at |
datetime
|
When the bookmark was created |
Folder
dataclass
¶
Folder(
id: str,
name: str,
parent_id: str | None = None,
color: str | None = None,
created_at: datetime = datetime.now(),
)
Represents a bookmark folder.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier (UUID) |
name |
str
|
Display name of the folder |
parent_id |
str | None
|
ID of parent folder for nesting (future use) |
color |
str | None
|
Background color as hex string (e.g., "#4a4a5a") or None for default |
created_at |
datetime
|
When the folder was created |
BookmarkManager
¶
Manages bookmarks and folders with TOML persistence.
Provides CRUD operations for bookmarks and folders, with automatic persistence to a TOML file in the user's config directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
Path | None
|
Directory for storing bookmarks file. Defaults to ~/.config/astronomo/ |
None
|
Source code in src/astronomo/bookmarks.py
add_bookmark
¶
Add a new bookmark.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The Gemini URL to bookmark |
required |
title
|
str
|
Display title for the bookmark |
required |
folder_id
|
str | None
|
Optional folder ID to place the bookmark in |
None
|
Returns:
| Type | Description |
|---|---|
Bookmark
|
The created Bookmark |
Source code in src/astronomo/bookmarks.py
add_folder
¶
Add a new folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Display name for the folder |
required |
Returns:
| Type | Description |
|---|---|
Folder
|
The created Folder |
Source code in src/astronomo/bookmarks.py
bookmark_exists
¶
get_all_folders
¶
get_bookmark
¶
get_bookmarks_in_folder
¶
Get all bookmarks in a specific folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_id
|
str | None
|
Folder ID, or None for root-level bookmarks |
required |
Returns:
| Type | Description |
|---|---|
list[Bookmark]
|
List of bookmarks in the specified folder |
Source code in src/astronomo/bookmarks.py
get_folder
¶
get_root_bookmarks
¶
remove_bookmark
¶
Remove a bookmark by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bookmark_id
|
str
|
ID of the bookmark to remove |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if bookmark was found and removed, False otherwise |
Source code in src/astronomo/bookmarks.py
remove_folder
¶
Remove a folder, moving its bookmarks to root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_id
|
str
|
ID of the folder to remove |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if folder was found and removed, False otherwise |
Source code in src/astronomo/bookmarks.py
rename_folder
¶
Rename a folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_id
|
str
|
ID of the folder to rename |
required |
name
|
str
|
New name for the folder |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if folder was found and renamed, False otherwise |
Source code in src/astronomo/bookmarks.py
update_bookmark
¶
Update a bookmark's properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bookmark_id
|
str
|
ID of the bookmark to update |
required |
title
|
str | None
|
New title (if provided) |
None
|
folder_id
|
str | None
|
New folder ID, None for root, or ... to keep current |
...
|
Returns:
| Type | Description |
|---|---|
bool
|
True if bookmark was found and updated, False otherwise |
Source code in src/astronomo/bookmarks.py
update_folder_color
¶
Update a folder's background color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
folder_id
|
str
|
ID of the folder to update |
required |
color
|
str | None
|
Hex color string (e.g., "#4a4a5a") or None for default |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if folder was found and updated, False otherwise |
Source code in src/astronomo/bookmarks.py
File Format¶
Bookmarks are stored in TOML format:
[folders.folder-uuid]
id = "folder-uuid"
name = "My Folder"
created_at = "2025-01-15T10:30:00"
[bookmarks.bookmark-uuid]
id = "bookmark-uuid"
url = "gemini://example.com/"
title = "Example Site"
folder_id = "folder-uuid" # Optional
created_at = "2025-01-15T10:30:00"
Example Usage¶
from astronomo.bookmarks import BookmarkManager, Bookmark, Folder
# Load bookmarks (creates file if needed)
manager = BookmarkManager()
# Create a folder
folder = manager.create_folder("Tech Sites")
# Add a bookmark to the folder
bookmark = manager.add_bookmark(
url="gemini://geminiprotocol.net/",
title="Gemini Protocol",
folder_id=folder.id,
)
# Get all bookmarks in a folder
bookmarks = manager.get_bookmarks_in_folder(folder.id)
# Save changes (automatic on modification)
manager.save()