| 1 |
# Cookidoo API |
| 2 |
|
| 3 |
[](https://pypi.org/p/cookidoo-api) |
| 4 |
|
| 5 |
An unofficial python package to access Cookidoo. |
| 6 |
|
| 7 |
[](https://github.com/miaucl/cookidoo-api/actions/workflows/unit-tests.yaml) |
| 8 |
[](https://github.com/miaucl/cookidoo-api/actions/workflows/smoke-test.yaml) |
| 9 |
[](https://codecov.io/gh/miaucl/cookidoo-api) |
| 10 |
[](https://github.com/miaucl/cookidoo-api/actions/workflows/ruff.yml) |
| 11 |
[](https://github.com/miaucl/cookidoo-api/actions/workflows/mypy.yaml) |
| 12 |
[](https://github.com/miaucl/cookidoo-api/actions/workflows/markdownlint.yml) |
| 13 |
|
| 14 |
[](https://github.com/sponsors/miaucl) |
| 15 |
[](https://patreon.com/miaucl) |
| 16 |
[](https://buymeacoffee.com/miaucl) |
| 17 |
[](https://paypal.me/sponsormiaucl) |
| 18 |
|
| 19 |
## Disclaimer |
| 20 |
|
| 21 |
The developers of this module are in no way endorsed by or affiliated with Cookidoo or Vorwerk, or any associated subsidiaries, logos or trademarks. |
| 22 |
|
| 23 |
## Installation |
| 24 |
|
| 25 |
`pip install cookidoo-api` |
| 26 |
|
| 27 |
## Documentation |
| 28 |
|
| 29 |
See below for usage examples. |
| 30 |
|
| 31 |
## Usage Example |
| 32 |
|
| 33 |
The API is based on the `aiohttp` library. Authentication uses the OAuth2 authorization-code flow (with PKCE) and authenticates requests with a bearer token; tokens can be persisted with `save_token`/`load_token`. A `CookieJar(unsafe=True)` is still required for the session, as the login redirect chain relies on cookies. |
| 34 |
|
| 35 |
Make sure to have stored your credentials in the top-level file `.env` as such, to loaded by `dotenv`. Alternatively, provide the environment variables by any other `dotenv` compatible means. |
| 36 |
|
| 37 |
```text |
| 38 |
[email protected] |
| 39 |
PASSWORD=password |
| 40 |
``` |
| 41 |
|
| 42 |
Your account credentials are all that is needed. The library logs in as a *public* OAuth2 client — authorization code with PKCE and no client secret — so there is nothing else to obtain or configure. See [OAuth2 client](https://miaucl.github.io/cookidoo-api/oauth-client/) if you want to override the client identifiers anyway. |
| 43 |
|
| 44 |
Run the [example script](https://github.com/miaucl/cookidoo-api/blob/master/example.py) and have a look at the inline comments for more explanation. |
| 45 |
|
| 46 |
## Exceptions |
| 47 |
|
| 48 |
In case something goes wrong during a request, several [exceptions](https://github.com/miaucl/cookidoo/blob/master/cookidoo_api/exceptions.py) can be thrown, all inheriting from `CookidooException`. |
| 49 |
|
| 50 |
### Another asyncio event loop is |
| 51 |
|
| 52 |
With the async calls, you might encounter an error that another asyncio event loop is already running on the same thread. This is expected behavior according to the asyncio.run() [documentation](https://docs.python.org/3/library/asyncio-runner.html#asyncio.run). You cannot use more than one aiohttp session per thread, reuse the existing one! |
| 53 |
|
| 54 |
### Exception ignored: RuntimeError: Event loop is closed |
| 55 |
|
| 56 |
Due to a known issue in some versions of aiohttp when using Windows, you might encounter a similar error to this: |
| 57 |
|
| 58 |
```python |
| 59 |
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x00000000> |
| 60 |
Traceback (most recent call last): |
| 61 |
File "C:\...\py38\lib\asyncio\proactor_events.py", line 116, in __del__ |
| 62 |
self.close() |
| 63 |
File "C:\...\py38\lib\asyncio\proactor_events.py", line 108, in close |
| 64 |
self._loop.call_soon(self._call_connection_lost, None) |
| 65 |
File "C:\...\py38\lib\asyncio\base_events.py", line 719, in call_soon |
| 66 |
self._check_closed() |
| 67 |
File "C:\...\py38\lib\asyncio\base_events.py", line 508, in _check_closed |
| 68 |
raise RuntimeError('Event loop is closed') |
| 69 |
RuntimeError: Event loop is closed |
| 70 |
``` |
| 71 |
|
| 72 |
You can fix this according to [this](https://stackoverflow.com/questions/68123296/asyncio-throws-runtime-error-with-exception-ignored) StackOverflow answer by adding the following line of code before executing the library: |
| 73 |
|
| 74 |
```python |
| 75 |
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) |
| 76 |
``` |
| 77 |
|
| 78 |
## Dev |
| 79 |
|
| 80 |
### Local Setup |
| 81 |
|
| 82 |
Setup the dev environment using VSCode, it is highly recommended. |
| 83 |
|
| 84 |
```bash |
| 85 |
python -m venv .venv |
| 86 |
source .venv/bin/activate |
| 87 |
pip install -r requirements_dev.txt |
| 88 |
``` |
| 89 |
|
| 90 |
Install [pre-commit](https://pre-commit.com) |
| 91 |
|
| 92 |
```bash |
| 93 |
pre-commit install |
| 94 |
|
| 95 |
# Run the commit hooks manually |
| 96 |
pre-commit run --all-files |
| 97 |
``` |
| 98 |
|
| 99 |
### Devcontainer & Docker Setup |
| 100 |
|
| 101 |
For developers using **VS Code**, the repository includes a fully configured `.devcontainer`. Simply open the project in VS Code and click **"Reopen in Container"**. All Python requirements, linters, and hooks will initialize automatically! |
| 102 |
|
| 103 |
Alternatively, you can manually run the development environment using standard Docker Compose. First, set up your configuration: |
| 104 |
|
| 105 |
```bash |
| 106 |
cp .env.example .env |
| 107 |
``` |
| 108 |
|
| 109 |
*(Update `.env` with your Cookidoo credentials.)* |
| 110 |
|
| 111 |
Then, run the container: |
| 112 |
|
| 113 |
```bash |
| 114 |
docker-compose up -d |
| 115 |
docker-compose exec dev bash |
| 116 |
``` |
| 117 |
|
| 118 |
Inside the container, you can run the same hooks and commands as locally: |
| 119 |
|
| 120 |
```bash |
| 121 |
pre-commit install |
| 122 |
pre-commit run --all-files |
| 123 |
pytest tests/ |
| 124 |
``` |
| 125 |
|
| 126 |
> **Note:** If using the Devcontainer, these VS Code extensions are automatically installed for you. |
| 127 |
|
| 128 |
Following VSCode integrations may be helpful: |
| 129 |
|
| 130 |
- [ruff](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) |
| 131 |
- [mypy](https://marketplace.visualstudio.com/items?itemName=matangover.mypy) |
| 132 |
- [markdownlint](https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint) |
| 133 |
|
| 134 |
### Raw API Requests |
| 135 |
|
| 136 |
The raw requests intercepted between the Cookidoo Android App and the backend can be found here `./docs/raw-api-requests`. They have been used to reconstruct the API which is implemented in this library. |
| 137 |
|
| 138 |
## Testing |
| 139 |
|
| 140 |
There is a set of tests based on the current behaviour of the API. |
| 141 |
|
| 142 |
### Unit tests |
| 143 |
|
| 144 |
The unit tests base on the recorded payloads captured between the server and the android app. They are a snapshot and might change. |
| 145 |
|
| 146 |
### Smoke tests |
| 147 |
|
| 148 |
The smoke tests implements a series of request querying the server. It tries to cover as much functionality as possible while not impacting the server too much (we want to stay nice and not get noticed ^^). Therefore, it still might be the case that something breaks without noticing. Further, as it is a github action, only **non-premium** are tested, as it is currently not deemed worth keeping premium subscription for this sole purpose (might change my mind with a few donations^^). Should something break for premium features, a temporary account with trial period is created easily. |
| 149 |
|
| 150 |
### Releasing |
| 151 |
|
| 152 |
A *final version* can only be released from the `master` branch. To pass the gates of the `publish` workflow, the version must match in both the `tag` and `cookidoo_api/__init__.py`. |
| 153 |
|
| 154 |
To release a prerelease version, it must be done from a feature branch (**not** `master`). Prerelease versions are explicitly marked as such on the GitHub release page. |
| 155 |
|
| 156 |
## Roadmap |
| 157 |
|
| 158 |
- [x] Add custom recipes to calendar and shopping list |
| 159 |
- [ ] Edit custom recipes |
| 160 |
- [ ] Create blank custom recipes (not copy existing) |