karakeep-python-api 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,256 @@
1
+ Metadata-Version: 2.4
2
+ Name: karakeep_python_api
3
+ Version: 0.1.0
4
+ Summary: Community python client for the Karakeep API.
5
+ Home-page: https://github.com/thiswillbeyourgithub/karakeep_python_api/
6
+ License: GPLv3
7
+ Keywords: rss,karakeep,hoarder,data-hoarding,python,api,feeds,openapi
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.32.3
15
+ Requires-Dist: loguru
16
+ Requires-Dist: pydantic>=2.0
17
+ Requires-Dist: click>=8.0
18
+ Provides-Extra: dev
19
+ Requires-Dist: beartype>=0.20.2; extra == "dev"
20
+ Requires-Dist: pytest>=8.3.4; extra == "dev"
21
+ Requires-Dist: build>=1.2.2.post1; extra == "dev"
22
+ Requires-Dist: twine>=6.1.0; extra == "dev"
23
+ Requires-Dist: bumpver>=2024.1130; extra == "dev"
24
+ Dynamic: classifier
25
+ Dynamic: description
26
+ Dynamic: description-content-type
27
+ Dynamic: home-page
28
+ Dynamic: keywords
29
+ Dynamic: license
30
+ Dynamic: license-file
31
+ Dynamic: provides-extra
32
+ Dynamic: requires-dist
33
+ Dynamic: requires-python
34
+ Dynamic: summary
35
+
36
+ # Karakeep Python API Client
37
+
38
+ [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
39
+ [![PyPI version](https://badge.fury.io/py/karakeep-python-api.svg)](https://badge.fury.io/py/karakeep-python-api) <!-- TODO: Add PyPI link once published -->
40
+
41
+ A community-developed Python client for the [Karakeep](https://karakeep.app/) API.
42
+
43
+ **Disclaimer:** This is an unofficial, community-driven project. The developers of Karakeep were not consulted during its creation. Use at your own discretion.
44
+
45
+ ## Table of Contents
46
+
47
+ - [Overview](#overview)
48
+ - [Current Status & Caveats](#current-status--caveats)
49
+ - [API Method Coverage](#api-method-coverage)
50
+ - [Installation](#installation)
51
+ - [Usage](#usage)
52
+ - [Environment Variables](#environment-variables)
53
+ - [Command Line Interface (CLI)](#command-line-interface-cli)
54
+ - [Python Library](#python-library)
55
+ - [Development](#development)
56
+ - [License](#license)
57
+
58
+ ## Overview
59
+
60
+ This library provides a Python interface (both a class and a command-line tool) to interact with a Karakeep instance's API.
61
+
62
+ The development process involved:
63
+
64
+ 1. Starting with the official Karakeep OpenAPI specification: [karakeep-openapi-spec.json](https://github.com/karakeep-app/karakeep/blob/main/packages/open-api/karakeep-openapi-spec.json).
65
+ 2. Generating Pydantic data models from the specification using [datamodel-code-generator](https://koxudaxi.github.io/datamodel-code-generator/).
66
+ 3. Using [aider.chat](https://aider.chat), an AI pair programming tool, to write the `KarakeepAPI` client class, the Click-based CLI, and the initial Pytest suite.
67
+
68
+ ## Current Status & Caveats
69
+
70
+ * **Experimental Methods:** The included Pytest suite currently only covers a subset of the available API methods (primarily 'get all' endpoints and client initialization). Methods *not* explicitly tested should be considered **experimental**.
71
+ * **Ongoing Development:** The author intends to improve and validate methods as they are needed for personal use cases. Contributions and bug reports are welcome!
72
+
73
+ ## API Method Coverage
74
+
75
+ The following table lists the public methods available in the `KarakeepAPI` class and indicates whether they are currently covered by the automated test suite (`tests/test_karakeep_api.py`). Methods marked as "No" should be used with caution as their behavior has not been automatically verified.
76
+
77
+ | Method Name | Tested | Remarks |
78
+ | -------------------------------- | :----: | -------------------------------------------- |
79
+ | `get_all_bookmarks` | ✅ | Tested with pagination. |
80
+ | `create_a_new_bookmark` | ✅ | Only tested for `type="link"`. |
81
+ | `search_bookmarks` | ✅ | Tested as part of create/delete flow. |
82
+ | `get_a_single_bookmark` | ✅ | Tested as part of create/delete flow. |
83
+ | `delete_a_bookmark` | ✅ | Tested as part of create/delete flow. |
84
+ | `update_a_bookmark` | ❌ | |
85
+ | `summarize_a_bookmark` | ❌ | |
86
+ | `attach_tags_to_a_bookmark` | ❌ | |
87
+ | `detach_tags_from_a_bookmark` | ❌ | |
88
+ | `get_highlights_of_a_bookmark` | ❌ | |
89
+ | `attach_asset` | ❌ | |
90
+ | `replace_asset` | ❌ | |
91
+ | `detach_asset` | ❌ | |
92
+ | `get_all_lists` | ✅ | |
93
+ | `create_a_new_list` | ✅ | Tested as part of create/delete flow. |
94
+ | `get_a_single_list` | ✅ | Tested as part of create/delete flow. |
95
+ | `delete_a_list` | ✅ | Tested as part of create/delete flow. |
96
+ | `update_a_list` | ❌ | |
97
+ | `get_a_bookmarks_in_a_list` | ❌ | |
98
+ | `add_a_bookmark_to_a_list` | ❌ | |
99
+ | `remove_a_bookmark_from_a_list` | ❌ | |
100
+ | `get_all_tags` | ✅ | |
101
+ | `get_a_single_tag` | ❌ | |
102
+ | `delete_a_tag` | ❌ | |
103
+ | `update_a_tag` | ❌ | |
104
+ | `get_a_bookmarks_with_the_tag` | ❌ | |
105
+ | `get_all_highlights` | ✅ | Tested with pagination. |
106
+ | `create_a_new_highlight` | ❌ | |
107
+ | `get_a_single_highlight` | ❌ | |
108
+ | `delete_a_highlight` | ❌ | |
109
+ | `update_a_highlight` | ❌ | |
110
+ | `get_current_user_info` | ✅ | Tested indirectly during client initialization. |
111
+ | `get_current_user_stats` | ✅ | |
112
+
113
+ ## Installation
114
+
115
+ It is recommended to use `uv` for faster installation:
116
+
117
+ ```bash
118
+ uv pip install karakeep-python-api
119
+ ```
120
+
121
+ Alternatively, use standard `pip`:
122
+
123
+ ```bash
124
+ pip install karakeep-python-api
125
+ ```
126
+
127
+ ## Usage
128
+
129
+ This package can be used as a Python library or as a command-line interface (CLI).
130
+
131
+ ### Environment Variables
132
+
133
+ The client can be configured using the following environment variables:
134
+
135
+ * `KARAKEEP_PYTHON_API_BASE_URL`: **Required**. The full base URL of your Karakeep API, including the `/api/v1/` path (e.g., `https://your-karakeep.example.com/api/v1/` or `https://try.karakeep.app/api/v1/`).
136
+ * `KARAKEEP_PYTHON_API_KEY`: **Required**. Your Karakeep API key (Bearer token).
137
+ * `KARAKEEP_PYTHON_API_VERIFY_SSL`: Set to `false` to disable SSL certificate verification (default: `true`).
138
+ * `KARAKEEP_PYTHON_API_VERBOSE`: Set to `true` to enable verbose debug logging for the client and CLI (default: `false`).
139
+ * `KARAKEEP_PYTHON_API_DISABLE_RESPONSE_VALIDATION`: Set to `true` to disable Pydantic validation of API responses. The client will return raw dictionary/list data instead of Pydantic models (default: `false`).
140
+
141
+ ### Command Line Interface (CLI)
142
+
143
+ The CLI dynamically generates commands based on the API methods. You need to provide your API key and base URL either via environment variables (recommended) or command-line options.
144
+
145
+ **Basic Structure:**
146
+
147
+ ```bash
148
+ python -m karakeep_python_api [GLOBAL_OPTIONS] <COMMAND> [COMMAND_OPTIONS]
149
+ ```
150
+
151
+ **Getting Help:**
152
+
153
+ ```bash
154
+ # General help and list of commands
155
+ python -m karakeep_python_api --help
156
+
157
+ # Help for a specific command
158
+ python -m karakeep_python_api get-all-bookmarks --help
159
+ ```
160
+
161
+ **Examples:**
162
+
163
+ ```bash
164
+ # List all tags (requires env vars set)
165
+ python -m karakeep_python_api get-all-tags
166
+
167
+ # Get the first page of bookmarks with a limit, overriding env vars if needed
168
+ # Note: Ensure the base URL includes the /api/v1/ path
169
+ python -m karakeep_python_api --base-url https://my.karakeep.com/api/v1/ --api-key YOUR_API_KEY get-all-bookmarks --limit 10
170
+
171
+ # Get all lists and pipe the JSON output to jq to extract the first list
172
+ python -m karakeep_python_api get-all-lists | jq '.[0]'
173
+
174
+ # Create a new bookmark from a link (body provided as JSON string)
175
+ python -m karakeep_python_api create-a-new-bookmark --data '{"type": "link", "url": "https://example.com"}'
176
+
177
+ # Dump the raw OpenAPI spec used by the client
178
+ python -m karakeep_python_api --dump-openapi-specification
179
+ ```
180
+
181
+ ### Python Library
182
+
183
+ Import the `KarakeepAPI` class and instantiate it.
184
+
185
+ ```python
186
+ import os
187
+ from karakeep_python_api import KarakeepAPI, APIError, AuthenticationError, datatypes
188
+
189
+ # Ensure required environment variables are set
190
+ # Example: os.environ["KARAKEEP_PYTHON_API_BASE_URL"] = "https://your-karakeep.example.com/api/v1/"
191
+ # Example: os.environ["KARAKEEP_PYTHON_API_KEY"] = "your_secret_api_key"
192
+
193
+ try:
194
+ # Initialize the client (reads from env vars by default)
195
+ client = KarakeepAPI(
196
+ # Optionally override env vars:
197
+ # base_url="https://another.karakeep.com",
198
+ # api_key="another_key",
199
+ # verbose=True,
200
+ # disable_response_validation=False
201
+ )
202
+
203
+ # Example: Get all lists
204
+ all_lists = client.get_all_lists()
205
+ if all_lists:
206
+ print(f"Retrieved {len(all_lists)} lists.")
207
+ # Access list properties (uses Pydantic models by default)
208
+ print(f"First list name: {all_lists[0].name}")
209
+ print(f"First list ID: {all_lists[0].id}")
210
+ else:
211
+ print("No lists found.")
212
+
213
+ # Example: Get first page of bookmarks
214
+ bookmarks_page = client.get_all_bookmarks(limit=5)
215
+ print(f"\nRetrieved {len(bookmarks_page.bookmarks)} bookmarks.")
216
+ if bookmarks_page.bookmarks:
217
+ print(f"First bookmark title: {bookmarks_page.bookmarks[0].title}")
218
+ if bookmarks_page.nextCursor:
219
+ print(f"Next page cursor: {bookmarks_page.nextCursor}")
220
+
221
+
222
+ except AuthenticationError as e:
223
+ print(f"Authentication failed: {e}")
224
+ except APIError as e:
225
+ print(f"An API error occurred: {e}")
226
+ except ValueError as e:
227
+ # Handles missing API key/base URL during initialization
228
+ print(f"Configuration error: {e}")
229
+ except Exception as e:
230
+ print(f"An unexpected error occurred: {e}")
231
+
232
+ ```
233
+
234
+ ## Development
235
+
236
+ 1. Clone the repository.
237
+ 2. Create a virtual environment and activate it.
238
+ 3. Install dependencies, including development tools (using `uv` recommended):
239
+
240
+ ```bash
241
+ uv pip install -e ".[dev]"
242
+ ```
243
+ 4. Set the required environment variables (`KARAKEEP_PYTHON_API_BASE_URL`, `KARAKEEP_PYTHON_API_KEY`) for running tests against a live instance.
244
+ 5. Run tests:
245
+
246
+ ```bash
247
+ pytest
248
+ ```
249
+
250
+ ## License
251
+
252
+ This project is licensed under the **GNU General Public License v3 (GPLv3)**. See the [LICENSE](LICENSE) file for details.
253
+
254
+ ---
255
+
256
+ *This README was generated with assistance from [aider.chat](https://aider.chat).*
@@ -0,0 +1,11 @@
1
+ karakeep_python_api/__init__.py,sha256=qk3MeIIvnCNAyYzJrv8dMKVXvA4ejLU3mhB3xFzdLDY,606
2
+ karakeep_python_api/__main__.py,sha256=luzDzVjSoWGIGjoNSlEPQ-jZTBMynHeSu71sNOn0Khk,21908
3
+ karakeep_python_api/datatypes.py,sha256=nVuaFB-BaNcTdzNqLvHBG0OlgoXdi0NxL0Rr_jqOPao,4189
4
+ karakeep_python_api/karakeep_api.py,sha256=z5xm7nJwUWUGRua08WKyMGVTW76F4C5Vbwmpbbi7KkE,72453
5
+ karakeep_python_api/openapi_reference.json,sha256=2sQRiQs8xwNFmsksqWGmqnsUMr8vqhHag9GNZDmnVUk,77104
6
+ karakeep_python_api-0.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
7
+ karakeep_python_api-0.1.0.dist-info/METADATA,sha256=U25aUdQqPxq-AAQXxHca7fbJy539Ys8vnbUA8nQKNPA,11666
8
+ karakeep_python_api-0.1.0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
9
+ karakeep_python_api-0.1.0.dist-info/entry_points.txt,sha256=n0leQp_IX2NivoWuUcaR9ZHwAvl_6yt-NcHWuCJyxNo,62
10
+ karakeep_python_api-0.1.0.dist-info/top_level.txt,sha256=X3VKqh9YAbPQp144db0Ko2C5Q2y6-nwpPgtnuCiSDmU,20
11
+ karakeep_python_api-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.3.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ karakeep = karakeep_python_api.__main__:cli