pyolivetree 2.0.0__tar.gz

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.
Files changed (29) hide show
  1. pyolivetree-2.0.0/.gitignore +25 -0
  2. pyolivetree-2.0.0/CHANGELOG.md +38 -0
  3. pyolivetree-2.0.0/LICENSE +21 -0
  4. pyolivetree-2.0.0/PKG-INFO +168 -0
  5. pyolivetree-2.0.0/README.md +132 -0
  6. pyolivetree-2.0.0/pyproject.toml +59 -0
  7. pyolivetree-2.0.0/src/pyolivetree/__init__.py +37 -0
  8. pyolivetree-2.0.0/src/pyolivetree/__main__.py +3 -0
  9. pyolivetree-2.0.0/src/pyolivetree/_http.py +116 -0
  10. pyolivetree-2.0.0/src/pyolivetree/async_client.py +131 -0
  11. pyolivetree-2.0.0/src/pyolivetree/cli.py +42 -0
  12. pyolivetree-2.0.0/src/pyolivetree/client.py +273 -0
  13. pyolivetree-2.0.0/src/pyolivetree/constants.py +101 -0
  14. pyolivetree-2.0.0/src/pyolivetree/exceptions.py +35 -0
  15. pyolivetree-2.0.0/src/pyolivetree/notes.py +174 -0
  16. pyolivetree-2.0.0/src/pyolivetree/py.typed +0 -0
  17. pyolivetree-2.0.0/src/pyolivetree/resources/__init__.py +27 -0
  18. pyolivetree-2.0.0/src/pyolivetree/resources/_base.py +20 -0
  19. pyolivetree-2.0.0/src/pyolivetree/resources/account.py +117 -0
  20. pyolivetree-2.0.0/src/pyolivetree/resources/ai.py +41 -0
  21. pyolivetree-2.0.0/src/pyolivetree/resources/firebase.py +24 -0
  22. pyolivetree-2.0.0/src/pyolivetree/resources/media.py +44 -0
  23. pyolivetree-2.0.0/src/pyolivetree/resources/messages.py +46 -0
  24. pyolivetree-2.0.0/src/pyolivetree/resources/products.py +55 -0
  25. pyolivetree-2.0.0/src/pyolivetree/resources/reading.py +53 -0
  26. pyolivetree-2.0.0/src/pyolivetree/resources/store.py +185 -0
  27. pyolivetree-2.0.0/src/pyolivetree/resources/sync.py +156 -0
  28. pyolivetree-2.0.0/src/pyolivetree/resources/telemetry.py +63 -0
  29. pyolivetree-2.0.0/src/pyolivetree/resources/web.py +61 -0
@@ -0,0 +1,25 @@
1
+ .env
2
+ .env.*
3
+ !.env.example
4
+ .venv/
5
+ env/
6
+ __pycache__/
7
+ *.py[cod]
8
+ .pytest_cache/
9
+ .coverage
10
+ htmlcov/
11
+ dist/
12
+ build/
13
+ *.egg-info/
14
+ docs/_build/
15
+ results/
16
+ .ruff_cache/
17
+ .mypy_cache/
18
+ scripts/
19
+
20
+ .DS_Store
21
+ notes.md
22
+ highlights.md
23
+ clips.md
24
+ *.db
25
+ .vscode/
@@ -0,0 +1,38 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.0.0] - 2026-11-08
9
+
10
+ ### Added
11
+
12
+ - `ot.sync.pull`, `page`, `push` and `table_schema` for notes, highlights, library and reading-plan data.
13
+ - `backup`, `annotations` and `to_markdown` for a local SQLite backup and Markdown export.
14
+ - `pyolivetree` command line (`backup`, `notes`, `highlights`, `clips`, `status`, `library`).
15
+ - `ot.store.all_products` to walk every page of a product listing.
16
+ - Smart Search `ot.ai.query` with book filters.
17
+ - `DataSet` enum for sync data sets; plain names still work.
18
+ - Convenience methods `ot.backup()`, `notes()`, `highlights()`, `clips()`, `status()`, `library()` (also on `AsyncOliveTree`).
19
+ - `--refresh` CLI flag; `library` prints every owned product; clear error when no backup exists.
20
+ - Automatic re-login and retry on expired tokens.
21
+
22
+ ### Changed
23
+
24
+ - Hand-written client organised by endpoint group (`account`, `store`, `products`, `sync`, `ai`,
25
+ `reading`, `media`, `messages`, `telemetry`, `web`, `firebase`). Main class is `OliveTree`;
26
+ `OliveTreeClient`, `AsyncOliveTreeClient` and `a`-prefixed async methods still work.
27
+ - Store and account requests include standard client fields, fixing empty `purchased` results.
28
+ - Sync requests use the bearer token.
29
+
30
+ ## [1.0.0] - 2026-06-27
31
+
32
+ ### Added
33
+
34
+ - Initial release of the `pyolivetree` Python client covering the Olive Tree Bible Reader API operations in OpenAPI spec 1.0.0.
35
+ - Synchronous `OliveTreeClient` and asynchronous `AsyncOliveTreeClient`.
36
+ - Credential loading from constructor arguments or `.env` file.
37
+ - Bearer, Basic, and HMAC authentication support.
38
+ - Sphinx documentation and usage examples.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Taiwo Kareem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyolivetree
3
+ Version: 2.0.0
4
+ Summary: Python client for the Olive Tree Bible app APIs: notes, highlights, library, Smart Search
5
+ Author: Taiwo Kareem
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: api-client,bible,bible-study,notes,olivetree
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Religion
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Religion
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Requires-Dist: httpx>=0.27
25
+ Provides-Extra: dev
26
+ Requires-Dist: black>=24; extra == 'dev'
27
+ Requires-Dist: build>=1.2; extra == 'dev'
28
+ Requires-Dist: pytest-cov>=5; extra == 'dev'
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Requires-Dist: ruff>=0.6; extra == 'dev'
31
+ Requires-Dist: twine>=5; extra == 'dev'
32
+ Provides-Extra: docs
33
+ Requires-Dist: furo>=2024.1; extra == 'docs'
34
+ Requires-Dist: sphinx>=7; extra == 'docs'
35
+ Description-Content-Type: text/markdown
36
+
37
+ # pyolivetree
38
+
39
+ Python client for the **Olive Tree Bible** APIs. Use it to pull your notes and highlights, browse your library, query Smart Search AI, and more.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install pyolivetree
45
+ cp .env.example .env # put your Olive Tree email + password in it
46
+ ```
47
+
48
+ ## Client
49
+
50
+ ```python
51
+ from pyolivetree import DataSet, OliveTree
52
+
53
+ with OliveTree() as ot: # logs in on first call that needs it
54
+ ot.sync.status() # latest change numbers for your data
55
+ for row in ot.sync.pull(DataSet.ANNOTATIONS): # or "annotations"
56
+ print(row["table_name"], row["datum"].get("title"))
57
+
58
+ owned = list(ot.store.all_products(ot.store.purchased()))
59
+ ot.store.product(36163) # product details
60
+ ot.products.download_links(36163) # XML with product download URLs
61
+ ot.ai.query("What does the Bible say about patience?", books=["James"])
62
+ ot.reading.verse_of_the_day("2026-11-08")
63
+ ot.media.cover(36163) # bytes (JPEG)
64
+ ```
65
+
66
+ ### Convenience methods
67
+
68
+ ```python
69
+ with OliveTree() as ot:
70
+ ot.backup() # mirror sync data into olivetree.db; later runs fetch only changes
71
+ ot.notes() # your notes in Bible order (syncs annotation changes first)
72
+ ot.highlights() # highlights, with the highlighter color
73
+ ot.clips() # verse text you saved
74
+ ot.status() # sync server status and change numbers
75
+ ot.library() # every product you own, across all pages
76
+ ```
77
+
78
+ `notes`, `highlights` and `clips` take `db="olivetree.db"` and `refresh=True`; pass `refresh=False` to read the local backup offline. Each item is the row's fields (`title`, `content`, `created_date`, …) plus `type`, `ref` (e.g. `"John 3:16-17"`) and `color`. `pyolivetree.to_markdown(items)` renders any of them as Markdown.
79
+
80
+ Async, with the same groups and methods:
81
+
82
+ ```python
83
+ import asyncio
84
+ from pyolivetree import AsyncOliveTree
85
+
86
+ async def main():
87
+ async with AsyncOliveTree() as ot:
88
+ home = await ot.store.home()
89
+ notes = await ot.sync.pull("annotations") # list
90
+
91
+ asyncio.run(main())
92
+ ```
93
+
94
+ The 1.x names still work: `OliveTreeClient`, `AsyncOliveTreeClient`, `install_id=`, and `a`-prefixed async methods (`await client.store.ahome()`). See [examples/](examples/).
95
+
96
+ Data sets are `DataSet.ANNOTATIONS`, `LIBRARY`, `DAILY_READING` and `BOOKSHELF`. Every sync method and `backup()` also accept the plain name (`"library"`) or the server name (`"managed_library"`).
97
+
98
+ Responses come back as JSON (`dict`/`list`), `str` for XML/HTML, or `bytes` for images. Errors raise `OliveTreeAuthError` (login/401) or `OliveTreeAPIError` (other HTTP errors), both subclasses of `OliveTreeError` with `.status`, `.code` and `.body`. An expired token triggers one automatic re-login. `ot.request(method, url, ...)` reaches anything not wrapped.
99
+
100
+ | Group | Methods |
101
+ |---|---|
102
+ | `ot.account` | `login`, `access_token`, `refresh_token`, `signup`, `forgot_password`, `web_handoff_token`, `subscription`, `add_variable_subscription_selections` |
103
+ | `ot.store` | `home`, `banner`, `featured_categories`, `library`, `purchased`, `wishlists`, `search`, `category`, `product`, `products`, `library_details`, `all_products`, `path`, `subscriptions_available`, `first_run_*`, `need_interests`, `paid_features`, `paid_features_marketing`, `ads`, `product_manifest`, `giveaway`, `allow_subscription_purchase`, `subscription_variable_product_selection`, `wishlist_add`, `wishlist_remove`, `register_subscription`, `validate_google_in_app_purchase`, `support_delete_account` |
104
+ | `ot.products` | `download_links`, `info`, `register`, `updates`, `email_signup`, `reading_templates` |
105
+ | `ot.sync` | `status`, `page`, `pull`, `table_schema`, `push`, `release_lock`, `possibly_bad_annotation_data` |
106
+ | `ot.ai` | `query`, `status`, `set_usage`, `models` |
107
+ | `ot.reading` | `daily_reading`, `recommended`, `verse_of_the_day`, `verse_of_the_day_image`, `now_reading`, `completed_message` |
108
+ | `ot.media` | `cover`, `cover_stack`, `product_image`, `reading_plan_image`, `reading_plan_list_image`, `stream` |
109
+ | `ot.messages` | `list`, `register_device`, `metrics` |
110
+ | `ot.telemetry` | `event_manifest`, `get_variant`, `set_variant`, `events`, `session_start`, `consent_receipt`, `location_settings`, `subscription_log_usage` |
111
+ | `ot.web` | `timeouts`, `appirater_config`, `app_to_web_bridge`, `product_page`, `bible_study_packs`, `manage_subscriptions`, `eula`, `privacy_policy`, `help_articles`, `help_login` |
112
+ | `ot.firebase` | `get`, `root` |
113
+
114
+ Calls that change your account: `sync.push`, `store.wishlist_*`, `store.register_subscription`, `store.validate_google_in_app_purchase`, `store.support_delete_account` (irreversible), `account.signup`, `ai.set_usage`, and the `telemetry` POSTs.
115
+
116
+ ## Notes backup and export
117
+
118
+ ```bash
119
+ pyolivetree backup # mirror your sync data into olivetree.db (re-runs fetch only changes)
120
+ pyolivetree notes --out notes.md # your notes as Markdown, grouped by Bible book (from the backup)
121
+ pyolivetree notes --refresh # sync changes first, then export
122
+ pyolivetree highlights --out highlights.md
123
+ pyolivetree clips # verse text you saved
124
+ pyolivetree library # every product you own (JSON)
125
+ pyolivetree status # sync server status (JSON)
126
+ ```
127
+
128
+ ```python
129
+ from pyolivetree import OliveTree, to_markdown
130
+ with OliveTree() as ot:
131
+ print(to_markdown(ot.notes()))
132
+ ```
133
+
134
+ `olivetree.db` is SQLite: every row is in `syncables` (`table_name`, `datum` JSON).
135
+
136
+ ## How auth works
137
+
138
+ - Login: `POST /store/br5/app/json/account/account_login` returns `authentication_token`. The client sends it as `OTAuthorization: Bearer <token>`.
139
+ - Store/account form posts include standard client fields (`install_id`, `platform`, `ReaderVersion`, `supportsProductDRM`, …). Without them, `purchased` comes back empty.
140
+ - Signed endpoints (`ai`, `messages`, `telemetry.events`, `session_start`) add a `signature` header: uppercase-hex HMAC-SHA512 of the body, using the client keys in `constants.py`. Set `OLIVE_TREE_HMAC_KEY` (hex or base64) or pass `hmac_key=` to use one key for everything.
141
+ - `ot.request(..., basic=True)` sends HTTP Basic auth with your username and password.
142
+
143
+ ## Known gaps
144
+
145
+ - `messages.list` returns 401 until a device is registered via `messages.register_device`. The body format for that call isn't confirmed.
146
+ - `sync.possibly_bad_annotation_data` is currently rejected by the server (401/410); `firebase` reads are refused (423/401); the help-center pages may return 403 to non-browser clients.
147
+ - Purchased books (study Bibles included) download as encrypted files. This client gets the download links but doesn't decrypt them.
148
+
149
+ ## Development
150
+
151
+ Needs [uv](https://docs.astral.sh/uv/).
152
+
153
+ ```bash
154
+ make install # .venv with dev + docs extras
155
+ make test # pytest
156
+ make coverage # pytest with coverage report
157
+ make lint # ruff check
158
+ make format # ruff format + black
159
+ make docs # Sphinx HTML in docs/_build/html
160
+ make security # dependency vulnerability scan
161
+ make run # run examples/sync_basic.py
162
+ make build check # build sdist/wheel and validate with twine
163
+ make publish-test # upload to TestPyPI (token in ~/.pypirc)
164
+ make publish # upload to PyPI (token in ~/.pypirc)
165
+ ```
166
+
167
+ Layout: `client.py` (auth, request, signing), `async_client.py`, `resources/` (one module per endpoint group),
168
+ `notes.py` (backup + Markdown), `cli.py`, `constants.py`, `exceptions.py`. The OpenAPI description is in `swagger.yml`; the docs manual is in `docs/manual/`.
@@ -0,0 +1,132 @@
1
+ # pyolivetree
2
+
3
+ Python client for the **Olive Tree Bible** APIs. Use it to pull your notes and highlights, browse your library, query Smart Search AI, and more.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install pyolivetree
9
+ cp .env.example .env # put your Olive Tree email + password in it
10
+ ```
11
+
12
+ ## Client
13
+
14
+ ```python
15
+ from pyolivetree import DataSet, OliveTree
16
+
17
+ with OliveTree() as ot: # logs in on first call that needs it
18
+ ot.sync.status() # latest change numbers for your data
19
+ for row in ot.sync.pull(DataSet.ANNOTATIONS): # or "annotations"
20
+ print(row["table_name"], row["datum"].get("title"))
21
+
22
+ owned = list(ot.store.all_products(ot.store.purchased()))
23
+ ot.store.product(36163) # product details
24
+ ot.products.download_links(36163) # XML with product download URLs
25
+ ot.ai.query("What does the Bible say about patience?", books=["James"])
26
+ ot.reading.verse_of_the_day("2026-11-08")
27
+ ot.media.cover(36163) # bytes (JPEG)
28
+ ```
29
+
30
+ ### Convenience methods
31
+
32
+ ```python
33
+ with OliveTree() as ot:
34
+ ot.backup() # mirror sync data into olivetree.db; later runs fetch only changes
35
+ ot.notes() # your notes in Bible order (syncs annotation changes first)
36
+ ot.highlights() # highlights, with the highlighter color
37
+ ot.clips() # verse text you saved
38
+ ot.status() # sync server status and change numbers
39
+ ot.library() # every product you own, across all pages
40
+ ```
41
+
42
+ `notes`, `highlights` and `clips` take `db="olivetree.db"` and `refresh=True`; pass `refresh=False` to read the local backup offline. Each item is the row's fields (`title`, `content`, `created_date`, …) plus `type`, `ref` (e.g. `"John 3:16-17"`) and `color`. `pyolivetree.to_markdown(items)` renders any of them as Markdown.
43
+
44
+ Async, with the same groups and methods:
45
+
46
+ ```python
47
+ import asyncio
48
+ from pyolivetree import AsyncOliveTree
49
+
50
+ async def main():
51
+ async with AsyncOliveTree() as ot:
52
+ home = await ot.store.home()
53
+ notes = await ot.sync.pull("annotations") # list
54
+
55
+ asyncio.run(main())
56
+ ```
57
+
58
+ The 1.x names still work: `OliveTreeClient`, `AsyncOliveTreeClient`, `install_id=`, and `a`-prefixed async methods (`await client.store.ahome()`). See [examples/](examples/).
59
+
60
+ Data sets are `DataSet.ANNOTATIONS`, `LIBRARY`, `DAILY_READING` and `BOOKSHELF`. Every sync method and `backup()` also accept the plain name (`"library"`) or the server name (`"managed_library"`).
61
+
62
+ Responses come back as JSON (`dict`/`list`), `str` for XML/HTML, or `bytes` for images. Errors raise `OliveTreeAuthError` (login/401) or `OliveTreeAPIError` (other HTTP errors), both subclasses of `OliveTreeError` with `.status`, `.code` and `.body`. An expired token triggers one automatic re-login. `ot.request(method, url, ...)` reaches anything not wrapped.
63
+
64
+ | Group | Methods |
65
+ |---|---|
66
+ | `ot.account` | `login`, `access_token`, `refresh_token`, `signup`, `forgot_password`, `web_handoff_token`, `subscription`, `add_variable_subscription_selections` |
67
+ | `ot.store` | `home`, `banner`, `featured_categories`, `library`, `purchased`, `wishlists`, `search`, `category`, `product`, `products`, `library_details`, `all_products`, `path`, `subscriptions_available`, `first_run_*`, `need_interests`, `paid_features`, `paid_features_marketing`, `ads`, `product_manifest`, `giveaway`, `allow_subscription_purchase`, `subscription_variable_product_selection`, `wishlist_add`, `wishlist_remove`, `register_subscription`, `validate_google_in_app_purchase`, `support_delete_account` |
68
+ | `ot.products` | `download_links`, `info`, `register`, `updates`, `email_signup`, `reading_templates` |
69
+ | `ot.sync` | `status`, `page`, `pull`, `table_schema`, `push`, `release_lock`, `possibly_bad_annotation_data` |
70
+ | `ot.ai` | `query`, `status`, `set_usage`, `models` |
71
+ | `ot.reading` | `daily_reading`, `recommended`, `verse_of_the_day`, `verse_of_the_day_image`, `now_reading`, `completed_message` |
72
+ | `ot.media` | `cover`, `cover_stack`, `product_image`, `reading_plan_image`, `reading_plan_list_image`, `stream` |
73
+ | `ot.messages` | `list`, `register_device`, `metrics` |
74
+ | `ot.telemetry` | `event_manifest`, `get_variant`, `set_variant`, `events`, `session_start`, `consent_receipt`, `location_settings`, `subscription_log_usage` |
75
+ | `ot.web` | `timeouts`, `appirater_config`, `app_to_web_bridge`, `product_page`, `bible_study_packs`, `manage_subscriptions`, `eula`, `privacy_policy`, `help_articles`, `help_login` |
76
+ | `ot.firebase` | `get`, `root` |
77
+
78
+ Calls that change your account: `sync.push`, `store.wishlist_*`, `store.register_subscription`, `store.validate_google_in_app_purchase`, `store.support_delete_account` (irreversible), `account.signup`, `ai.set_usage`, and the `telemetry` POSTs.
79
+
80
+ ## Notes backup and export
81
+
82
+ ```bash
83
+ pyolivetree backup # mirror your sync data into olivetree.db (re-runs fetch only changes)
84
+ pyolivetree notes --out notes.md # your notes as Markdown, grouped by Bible book (from the backup)
85
+ pyolivetree notes --refresh # sync changes first, then export
86
+ pyolivetree highlights --out highlights.md
87
+ pyolivetree clips # verse text you saved
88
+ pyolivetree library # every product you own (JSON)
89
+ pyolivetree status # sync server status (JSON)
90
+ ```
91
+
92
+ ```python
93
+ from pyolivetree import OliveTree, to_markdown
94
+ with OliveTree() as ot:
95
+ print(to_markdown(ot.notes()))
96
+ ```
97
+
98
+ `olivetree.db` is SQLite: every row is in `syncables` (`table_name`, `datum` JSON).
99
+
100
+ ## How auth works
101
+
102
+ - Login: `POST /store/br5/app/json/account/account_login` returns `authentication_token`. The client sends it as `OTAuthorization: Bearer <token>`.
103
+ - Store/account form posts include standard client fields (`install_id`, `platform`, `ReaderVersion`, `supportsProductDRM`, …). Without them, `purchased` comes back empty.
104
+ - Signed endpoints (`ai`, `messages`, `telemetry.events`, `session_start`) add a `signature` header: uppercase-hex HMAC-SHA512 of the body, using the client keys in `constants.py`. Set `OLIVE_TREE_HMAC_KEY` (hex or base64) or pass `hmac_key=` to use one key for everything.
105
+ - `ot.request(..., basic=True)` sends HTTP Basic auth with your username and password.
106
+
107
+ ## Known gaps
108
+
109
+ - `messages.list` returns 401 until a device is registered via `messages.register_device`. The body format for that call isn't confirmed.
110
+ - `sync.possibly_bad_annotation_data` is currently rejected by the server (401/410); `firebase` reads are refused (423/401); the help-center pages may return 403 to non-browser clients.
111
+ - Purchased books (study Bibles included) download as encrypted files. This client gets the download links but doesn't decrypt them.
112
+
113
+ ## Development
114
+
115
+ Needs [uv](https://docs.astral.sh/uv/).
116
+
117
+ ```bash
118
+ make install # .venv with dev + docs extras
119
+ make test # pytest
120
+ make coverage # pytest with coverage report
121
+ make lint # ruff check
122
+ make format # ruff format + black
123
+ make docs # Sphinx HTML in docs/_build/html
124
+ make security # dependency vulnerability scan
125
+ make run # run examples/sync_basic.py
126
+ make build check # build sdist/wheel and validate with twine
127
+ make publish-test # upload to TestPyPI (token in ~/.pypirc)
128
+ make publish # upload to PyPI (token in ~/.pypirc)
129
+ ```
130
+
131
+ Layout: `client.py` (auth, request, signing), `async_client.py`, `resources/` (one module per endpoint group),
132
+ `notes.py` (backup + Markdown), `cli.py`, `constants.py`, `exceptions.py`. The OpenAPI description is in `swagger.yml`; the docs manual is in `docs/manual/`.
@@ -0,0 +1,59 @@
1
+ [project]
2
+ name = "pyolivetree"
3
+ version = "2.0.0"
4
+ description = "Python client for the Olive Tree Bible app APIs: notes, highlights, library, Smart Search"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.10"
9
+ authors = [{ name = "Taiwo Kareem" }]
10
+ keywords = ["olivetree", "bible", "bible-study", "notes", "api-client"]
11
+ classifiers = [
12
+ "Development Status :: 4 - Beta",
13
+ "Intended Audience :: Developers",
14
+ "Intended Audience :: Religion",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Topic :: Religion",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ "Typing :: Typed",
26
+ ]
27
+ dependencies = ["httpx>=0.27"]
28
+
29
+ [project.optional-dependencies]
30
+ dev = ["pytest>=8", "pytest-cov>=5", "ruff>=0.6", "black>=24", "build>=1.2", "twine>=5"]
31
+ docs = ["sphinx>=7", "furo>=2024.1"]
32
+
33
+ [project.scripts]
34
+ pyolivetree = "pyolivetree.cli:main"
35
+
36
+ [build-system]
37
+ requires = ["hatchling>=1.26"]
38
+ build-backend = "hatchling.build"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/pyolivetree"]
42
+
43
+ [tool.hatch.build.targets.sdist]
44
+ include = ["src", "README.md", "LICENSE", "CHANGELOG.md", "pyproject.toml"]
45
+ exclude = ["docs", "tests"]
46
+
47
+ [tool.pytest.ini_options]
48
+ testpaths = ["tests"]
49
+
50
+ [tool.black]
51
+ line-length = 110
52
+ target-version = ["py310"]
53
+
54
+ [tool.ruff]
55
+ line-length = 110
56
+ target-version = "py310"
57
+
58
+ [tool.ruff.lint]
59
+ select = ["E", "F", "I", "W", "UP", "B"]
@@ -0,0 +1,37 @@
1
+ """Python client for the Olive Tree Bible.
2
+
3
+ Example:
4
+ >>> from pyolivetree import OliveTree # doctest: +SKIP
5
+ >>> with OliveTree() as ot:
6
+ ... ot.sync.status()
7
+ """
8
+
9
+ from importlib.metadata import PackageNotFoundError, version
10
+
11
+ from pyolivetree._http import sign_body
12
+ from pyolivetree.async_client import AsyncOliveTree, AsyncOliveTreeClient
13
+ from pyolivetree.client import OliveTree, OliveTreeClient
14
+ from pyolivetree.constants import DataSet
15
+ from pyolivetree.exceptions import OliveTreeAPIError, OliveTreeAuthError, OliveTreeError
16
+ from pyolivetree.notes import annotations, backup, to_markdown, verse_ref
17
+
18
+ try:
19
+ __version__ = version("pyolivetree")
20
+ except PackageNotFoundError: # running from a source checkout
21
+ __version__ = "0.0.0"
22
+
23
+ __all__ = [
24
+ "AsyncOliveTree",
25
+ "AsyncOliveTreeClient",
26
+ "DataSet",
27
+ "OliveTree",
28
+ "OliveTreeAPIError",
29
+ "OliveTreeAuthError",
30
+ "OliveTreeClient",
31
+ "OliveTreeError",
32
+ "annotations",
33
+ "backup",
34
+ "sign_body",
35
+ "to_markdown",
36
+ "verse_ref",
37
+ ]
@@ -0,0 +1,3 @@
1
+ from pyolivetree.cli import main
2
+
3
+ main()
@@ -0,0 +1,116 @@
1
+ """Small helpers: .env loading, request signing and response parsing."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import binascii
7
+ import hashlib
8
+ import hmac
9
+ import os
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ import httpx
14
+
15
+ from pyolivetree.constants import HMAC_KEYS
16
+ from pyolivetree.exceptions import OliveTreeAPIError, OliveTreeAuthError
17
+
18
+
19
+ def load_dotenv(path: str = ".env") -> None:
20
+ """Load ``KEY=VALUE`` lines into :data:`os.environ`, keeping values already set.
21
+
22
+ Args:
23
+ path: File to read. Missing files are ignored.
24
+ """
25
+ if not os.path.isfile(path):
26
+ return
27
+ for line in Path(path).read_text().splitlines():
28
+ key, sep, val = line.partition("=")
29
+ if sep and not line.lstrip().startswith("#"):
30
+ os.environ.setdefault(key.strip(), val.strip().strip("\"'"))
31
+
32
+
33
+ def sign_body(body: bytes, profile: str = "telemetry", key: bytes | None = None) -> str:
34
+ """Compute the ``signature`` header required by signed endpoints.
35
+
36
+ Args:
37
+ body: Exact request body bytes.
38
+ profile: Key name in :data:`~pyolivetree.constants.HMAC_KEYS`
39
+ (``"telemetry"``, ``"ai"``, ``"consent"`` or ``"features"``).
40
+ key: Use this key instead of the profile's key.
41
+
42
+ Returns:
43
+ Uppercase hex HMAC-SHA512 digest.
44
+
45
+ Raises:
46
+ OliveTreeAuthError: If ``profile`` is unknown and no ``key`` is given.
47
+ """
48
+ if key is None:
49
+ try:
50
+ key = HMAC_KEYS[profile]
51
+ except KeyError:
52
+ raise OliveTreeAuthError(f"Unknown HMAC profile: {profile!r}") from None
53
+ return hmac.new(key, body, hashlib.sha512).hexdigest().upper()
54
+
55
+
56
+ def parse_hmac_key(raw: str | bytes | None) -> bytes | None:
57
+ """Decode an HMAC key given as hex, base64 or raw bytes.
58
+
59
+ Args:
60
+ raw: Key material, e.g. from ``OLIVE_TREE_HMAC_KEY``. Empty means no override.
61
+
62
+ Returns:
63
+ Key bytes, or ``None`` if ``raw`` is empty.
64
+
65
+ Raises:
66
+ ValueError: If a string is neither hex nor base64.
67
+ """
68
+ if not raw:
69
+ return None
70
+ if isinstance(raw, bytes):
71
+ return raw
72
+ text = raw.strip()
73
+ try:
74
+ return bytes.fromhex(text)
75
+ except ValueError:
76
+ pass
77
+ try:
78
+ return base64.b64decode(text, validate=True)
79
+ except binascii.Error:
80
+ raise ValueError("OLIVE_TREE_HMAC_KEY must be hex or base64") from None
81
+
82
+
83
+ def parse_response(r: httpx.Response) -> Any:
84
+ """Decode a response by content type and raise on errors.
85
+
86
+ Args:
87
+ r: The HTTP response.
88
+
89
+ Returns:
90
+ Parsed JSON, ``str`` for text/XML/HTML, otherwise ``bytes``.
91
+
92
+ Raises:
93
+ OliveTreeAuthError: On HTTP 401 or ``{"authenticated": false}``.
94
+ OliveTreeAPIError: On any other HTTP status >= 400.
95
+ """
96
+ ctype = r.headers.get("content-type", "")
97
+ body: Any = r.content
98
+ if "json" in ctype or r.content[:1] in (b"{", b"["):
99
+ try:
100
+ body = r.json()
101
+ except ValueError:
102
+ body = r.text
103
+ elif ctype.startswith("text/") or "xml" in ctype or "html" in ctype:
104
+ body = r.text
105
+ failed = isinstance(body, dict) and body.get("authenticated") is False
106
+ if r.status_code >= 400 or failed:
107
+ code = body.get("errorCode") if isinstance(body, dict) else None
108
+ msg = body.get("error") if isinstance(body, dict) else str(body)[:200]
109
+ cls = OliveTreeAuthError if failed or r.status_code == 401 else OliveTreeAPIError
110
+ raise cls(
111
+ f"{r.request.method} {r.request.url.path}: HTTP {r.status_code}: {msg}",
112
+ r.status_code,
113
+ code,
114
+ body,
115
+ )
116
+ return body