The official SDK for integrating homelessness data into the Comhom Platform.
Project description
comhom-sdk
Official Python SDK for integrating homelessness service data into the Comhom Platform.
Upload, validate, and manage beneficiary answer data from JSON or CSV files — via a Python API or the command line.
Features
- Upload answers in JSON or CSV format, validated against the live platform schema
- Validate files locally before sending data
- Generate synthetic test data that conforms to your organization's schema
- Delete all answers for a beneficiary in sandbox or production
- Python API for scripting and pipeline integration
Installation
pip install comhom-sdk
Requires Python 3.10+. Dependencies are installed automatically.
Quick start
Python API
from comhom_sdk import (
fetch_answer_schema,
load_api_key_from_file,
load_answers,
upload_answers,
validate_answer_items,
)
api_key = load_api_key_from_file("comhom.key")
answers = load_answers("answers.json")
schema = fetch_answer_schema(api_key=api_key)
validate_answer_items(answers, schema)
result = upload_answers(
api_key=api_key,
answers=answers,
sandbox=True,
)
print(result) # {"created": ..., "updated": ..., "skipped": ...}
Command line
python -m comhom_sdk upload \
--input-file answers.json \
--api-key-file comhom.key
By default, uploads target sandbox. Add --production for production.
Prerequisites
- API key — generate one on the Comhom platform. It is downloaded as
comhom.key, which the SDK uses by default. - Answer file — JSON or CSV with the required fields (see below).
Store your API key in a plain text file containing only the key:
your-api-key-here
Keep comhom.key out of source control.
Answer data format
Each row is one answer. Required fields:
| Field | Description |
|---|---|
respondent_code |
Stable, pseudonymous identifier for the respondent |
question_code |
Code of the question being answered |
value |
The answer (format depends on question type; see below) |
answered_at |
Date the answer was collected (YYYY-MM-DD) |
consent_signed |
Whether the respondent consented to data use (true / false) |
Only rows with consent_signed: true are loaded.
Question codes and values
Valid question_code values come from the Comhom question catalogue. Examples:
question_code |
Type | Example value |
|---|---|---|
sex_gender |
Single choice | cisgender_woman |
age |
Single choice | 25_34 |
nationality |
Single choice | national_country |
A2 |
Date | 2026-01-10 |
A4 |
Single choice | programme_completion |
A5 |
Program | housing_first (your org's program code) |
A6 |
Multiple choice | ["cm", "hn"] (CSV: `cm |
Value formats:
- Single choice — one option code (e.g.
sex_gender→cisgender_woman) - Multiple choice — a list of option codes (JSON:
["cm", "hn"]; CSV:cm|hn) - Date —
YYYY-MM-DD(e.g.A2→2026-01-10) - Program (A5) — a program
codefrom your organization (created on the platform first)
JSON
Use either a top-level array of answers, or an object with an answers array:
[
{
"respondent_code": "hash_7f3a9c2e",
"question_code": "sex_gender",
"answered_at": "2026-06-15",
"consent_signed": true,
"value": "cisgender_woman"
},
{
"respondent_code": "hash_7f3a9c2e",
"question_code": "A6",
"answered_at": "2026-06-15",
"consent_signed": true,
"value": ["cm", "hn"]
}
]
CSV
Required columns: respondent_code, question_code, answered_at, consent_signed, value.
respondent_code,question_code,answered_at,consent_signed,value
hash_7f3a9c2e,sex_gender,2026-06-15,true,cisgender_woman
hash_7f3a9c2e,A6,2026-06-15,true,cm|hn
For multiple choice in CSV, join option codes with |. A single selected option can be written as the bare code (e.g. cm).
answered_at is the collection date for each answer. If your source system does not track per-answer timestamps, use one date for the whole export.
Upload behavior
Microvariables (questions with retain_history=true):
- Duplicate rows for the same beneficiary/question/date in one file: last row wins
- Same value as the latest known snapshot on or before that date: skipped (safe to re-upload)
- Same date with a changed value: updated
- New date with a changed value: new history row created
Mesovariables (questions with retain_history=false, e.g. A2–A6):
- At most one stored answer per beneficiary/question/environment
- Re-upload overwrites value and
answered_atin place; older snapshots are removed - Duplicate rows for the same beneficiary/question in one file: last row wins
Command reference
upload
python -m comhom_sdk upload -i answers.json -k comhom.key
| Option | Short | Required | Description |
|---|---|---|---|
--input-file |
-i |
Yes | Path to .json or .csv file |
--api-key-file |
-k |
No | Path to API key file (default: comhom.key) |
--production |
-p |
No | Upload to production (default: sandbox) |
--batch-size |
-b |
No | Answers per request (default 500) |
validate
Validate a file locally without uploading:
python -m comhom_sdk validate -i answers.json --errors-file errors.csv
| Option | Short | Required | Description |
|---|---|---|---|
--input-file |
-i |
Yes | Path to .json or .csv file |
--api-key-file |
-k |
No | Path to API key file (default: comhom.key) |
--errors-file |
-e |
No | Write validation errors to CSV on failure |
generate
Generate synthetic answers using your organization's live schema:
python -m comhom_sdk generate \
-n 1000 -c 20 -o synthetic_answers.json -k comhom.key
| Option | Short | Required | Description |
|---|---|---|---|
--total-answers |
-n |
Yes | Number of synthetic answers to generate |
--output-file |
-o |
Yes | Output path (.json or .csv) |
--respondent-count |
-c |
No | Number of respondent codes (default 1) |
--respondent-prefix |
-p |
No | Prefix for respondent codes (default R) |
--answered-at |
-a |
No | Fixed date (YYYY-MM-DD) for all answers |
--days-back |
-d |
No | Random date within last N days (default 365) |
--seed |
-s |
No | Seed for deterministic generation |
--api-key-file |
-k |
No | Path to API key file (default: comhom.key) |
delete
Delete all answers for a beneficiary:
python -m comhom_sdk delete -r hash_7f3a9c2e -k comhom.key
| Option | Short | Required | Description |
|---|---|---|---|
--respondent-code |
-r |
Yes | Beneficiary code to delete |
--api-key-file |
-k |
No | Path to API key file (default: comhom.key) |
--production |
-p |
No | Delete production data (default: sandbox) |
Python API reference
| Function | Description |
|---|---|
load_api_key_from_file(path) |
Read API key from a text file |
load_answers(path) |
Load answers from JSON or CSV |
save_answers(answers, path) |
Write answers to JSON or CSV |
fetch_answer_schema(api_key=...) |
Download the org-specific upload schema |
validate_answer_items(answers, schema) |
Validate answers against the schema |
collect_validation_errors(answers, schema) |
Return detailed validation errors |
upload_answers(api_key, answers, sandbox=True) |
Upload validated answers in batches |
generate_synthetic_answers(schema, ...) |
Generate schema-conformant test data |
delete_beneficiary_answers(api_key, respondent_code, sandbox=True) |
Delete a beneficiary's answers |
All network or validation failures raise UploadSDKError.
Troubleshooting
Upload succeeds with counts for created, updated, and skipped rows.
Upload fails with an error message; no further batches are sent.
Validation fails — use --errors-file to export every error row for review.
Common issues:
- Wrong API key or insufficient permissions
- Missing required CSV columns
- Invalid date format (must be
YYYY-MM-DD) consent_signednot set totrue- Invalid
question_codeor option code - A5
valuenot matching a program code in your organization - Extra fields that do not match the schema
License
MIT License. Copyright (c) 2025 Socialit.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file comhom_sdk-0.1.2.tar.gz.
File metadata
- Download URL: comhom_sdk-0.1.2.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
722ed08a2b4b0f7d2b9ca3318adf5370df886de6af5e95f52003f98f1bec4364
|
|
| MD5 |
be087502f6313e178bc563fbb6c97dc7
|
|
| BLAKE2b-256 |
32e8c7420336ef1bca4c2e4c8190bca580cbbb24c661c08941e1f924aa92c7e8
|
File details
Details for the file comhom_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: comhom_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
866dedf8ddf46fbd1593faf793256c89c6d09e50d3689828957c686d0a243a5d
|
|
| MD5 |
959e442a854bca75f5275bc214c9e47c
|
|
| BLAKE2b-256 |
250b381097262898e9b4c2f8eabe6df42f99ee70143650d17dafe23bd9e79489
|