mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 10:56:29 +03:00
Why: When the deltachat-rpc-server encounters a fatal error during early startup (e.g., when the accounts directory is invalid, a file instead of a dir, or otherwise inaccessible), it exits. The Python RPC client previously lacked a structured way to wait for the server to be fully initialized or to detect early startup failures gracefully. This led to hanging tests or obscure broken pipe errors rather than clear initialization errors. How: - The RPC server now sends a JSON-RPC notification on stdout at startup: - "ready" with core_version, server_path, and accounts_dir on success - "init_error" with error message if accounts directory initialization fails - The Python RPC client reads the first line from stdout to ensure the server is ready. - The Python client raises JsonRpcError on init_error, enabling early failure detection and fast-failing rather than stalling. - Added tests to ensure the client fails immediately on invalid dirs.
64 lines
1.5 KiB
Markdown
64 lines
1.5 KiB
Markdown
# Delta Chat RPC python client
|
|
|
|
RPC client connects to standalone Delta Chat RPC server `deltachat-rpc-server`
|
|
and provides asynchronous interface to it.
|
|
`rpc.start()` blocks until the server is initialized
|
|
and will raise an error if initialization fails
|
|
(e.g. if the accounts directory could not be used).
|
|
|
|
## Getting started
|
|
|
|
To use Delta Chat RPC client, first build a `deltachat-rpc-server` with `cargo build -p deltachat-rpc-server`
|
|
or download a prebuilt release.
|
|
Install it anywhere in your `PATH`.
|
|
|
|
[Create a virtual environment](https://docs.python.org/3/library/venv.html)
|
|
if you don't have one already and activate it.
|
|
```
|
|
$ python -m venv env
|
|
$ . env/bin/activate
|
|
```
|
|
|
|
Install `deltachat-rpc-client` from source:
|
|
```
|
|
$ cd deltachat-rpc-client
|
|
$ pip install .
|
|
```
|
|
|
|
## Testing
|
|
|
|
1. Build `deltachat-rpc-server` with `cargo build -p deltachat-rpc-server`.
|
|
2. Install tox `pip install -U tox`
|
|
3. Run `CHATMAIL_DOMAIN=nine.testrun.org PATH="../target/debug:$PATH" tox`.
|
|
|
|
Additional arguments to `tox` are passed to pytest, e.g. `tox -- -s` does not capture test output.
|
|
|
|
|
|
## Activating current checkout of deltachat-rpc-client and -server for development
|
|
|
|
Go to root repository directory and run:
|
|
```
|
|
$ scripts/make-rpc-testenv.sh
|
|
$ source venv/bin/activate
|
|
```
|
|
|
|
## Using in REPL
|
|
|
|
Setup a development environment:
|
|
```
|
|
$ tox --devenv env
|
|
$ . env/bin/activate
|
|
```
|
|
|
|
```
|
|
$ python
|
|
>>> from deltachat_rpc_client import *
|
|
>>> rpc = Rpc()
|
|
>>> rpc.start()
|
|
>>> dc = DeltaChat(rpc)
|
|
>>> system_info = dc.get_system_info()
|
|
>>> system_info["level"]
|
|
'awesome'
|
|
>>> rpc.close()
|
|
```
|