PyLimeRPC 0.2.0 — prompts.md Prompt 1-4

- responses.py: get_summary() (raw RPC get_summary), count_responses() ->
  frozen ResponseCounts(completed, incomplete, total), export_responses_auto()
  with automatic format fallback (xlsx -> xls -> csv) on IWriter errors
- utils.py: summary_counts_full() -> (completed, incomplete, total) with
  per-LS-version key fallbacks; summary_counts left untouched
- surveys.py: get_survey_by_sid() (dict | None), get_survey_info() ->
  frozen SurveyInfo(sid, title, active)
- tokens.py: documented that extra/custom token attributes (attribute_1, ...)
  pass through unchanged in add_participants/list_participants
- LsClient: get_summary, count_responses, get_survey_by_sid, get_survey_info,
  export_responses_auto; __all__ + re-exports updated
- README: new "Response counts & summary" section + usage examples
- .gitignore: prompts.md added (local-only docs, like werkdocument.md)
- version 0.1.0 -> 0.2.0 (__init__.py + pyproject.toml)
- tests: +27 FakeRpc unit tests (96 passed, 2 deselected)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-20 11:56:03 +01:00
commit 6822eab467

View file

@ -41,8 +41,8 @@ pylimerpc/
config.py # .env reading (standard library, no python-dotenv)
rpc.py # JSON-RPC transport: build request, POST, handle errors
session.py # get_session_key / release_session_key
surveys.py # list_surveys, get_survey_properties
responses.py # export_responses (CSV/JSON), export_statistics
surveys.py # list_surveys, get_survey_properties, get_survey_by_sid, get_survey_info
responses.py # export_responses (CSV/JSON), export_responses_auto, export_statistics, get_summary, count_responses
tokens.py # token management: add/list/delete participants
errors.py # LsConnectionError, LsApiError, LsAuthError
utils.py # shared helpers
@ -74,6 +74,8 @@ cfg = LsConfig.from_dotenv(".env")
with LsClient(cfg) as ls: # opens a session, releases the key on exit
surveys = ls.list_surveys() # all surveys of this user
props = ls.get_survey_properties(surveys[0]["sid"])
info = ls.get_survey_info(surveys[0]["sid"]) # → SurveyInfo(sid, title, active) or None
survey = ls.get_survey_by_sid(surveys[0]["sid"]) # raw dict from list_surveys, or None
```
Low level (without session management): `RpcClient.from_config(cfg).call(method, params)`.
@ -81,15 +83,49 @@ Low level (without session management): `RpcClient.from_config(cfg).call(method,
```python
with LsClient(cfg) as ls:
data = ls.export_responses(sid, doc_type="csv", output_path="output/") # → Path
# automatic format fallback (xlsx → xls → csv) when the LS install lacks a writer:
data, used_format = ls.export_responses_auto(sid) # → (bytes | Path, "xls")
stats = ls.export_statistics(sid) # → bytes
ls.add_participants(sid, [{"email": "a@b.c", "firstname": "A"}])
participants = ls.list_participants(sid)
summary = ls.get_summary(sid) # raw dict
counts = ls.count_responses(sid) # → ResponseCounts(completed, incomplete, total)
# extra/custom token attributes (attribute_1, ...) pass through unchanged:
ls.add_participants(sid, [{"email": "a@b.c", "firstname": "A", "attribute_1": "blue"}])
participants = ls.list_participants(sid) # dicts include any attribute_* keys
ls.delete_participants(sid, [participants[0]["tid"]])
```
LS7 RemoteControl methods: `export_responses`, `export_statistics`,
LS7 RemoteControl methods: `export_responses`, `export_statistics`, `get_summary`,
`add_participants`, `list_participants`, `delete_participants` (base64 exports
are decoded automatically).
are decoded automatically). `count_responses` reads the response counts from
the `get_summary` result (key names differ per LS version; missing/invalid
values count as 0).
## Response counts & summary
`get_summary` returns the raw summary dict of a survey (LS7 RPC `get_summary`,
params `[session_key, sid]`); `count_responses` turns it into a frozen
`ResponseCounts` dataclass:
```python
from pylimerpc import LsClient, LsConfig
cfg = LsConfig.from_dotenv(".env")
with LsClient(cfg) as ls:
summary = ls.get_summary(sid) # raw dict, e.g. {"completed_responses": 14, ...}
counts = ls.count_responses(sid) # ResponseCounts(completed=14, incomplete=41, total=55)
print(counts.completed, counts.incomplete, counts.total)
```
Key names in the summary differ per LS version: `completed_responses`
(fallbacks `responses_completed` / `completed`), `incomplete_responses`
(fallback `in_progress_responses`), and `full_responses` for the total when
present (otherwise `total = completed + incomplete`). Missing or invalid
values count as 0.
Related: `ls.get_survey_info(sid)` → `SurveyInfo(sid, title, active)` or `None`
("does not exist / not active / title" in one call), and
`ls.export_responses_auto(sid)` → `(data, used_format)` with automatic format
fallback (xlsx → xls → csv) when the LS installation lacks a writer.
Errors: `LsConnectionError` (server unreachable/HTTP error), `LsApiError`
(JSON-RPC error, with `rpc_code`/`rpc_message`), `LsAuthError` (login refused).