sesamehr 0.1.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.
- sesamehr-0.1.0/.github/workflows/publish.yml +28 -0
- sesamehr-0.1.0/.github/workflows/test.yml +20 -0
- sesamehr-0.1.0/.gitignore +11 -0
- sesamehr-0.1.0/LICENSE +21 -0
- sesamehr-0.1.0/PARITY.md +95 -0
- sesamehr-0.1.0/PKG-INFO +157 -0
- sesamehr-0.1.0/README.md +133 -0
- sesamehr-0.1.0/pyproject.toml +49 -0
- sesamehr-0.1.0/scripts/smoke.py +157 -0
- sesamehr-0.1.0/src/sesamehr/__init__.py +149 -0
- sesamehr-0.1.0/src/sesamehr/_base.py +19 -0
- sesamehr-0.1.0/src/sesamehr/_fetch.py +64 -0
- sesamehr-0.1.0/src/sesamehr/auth.py +135 -0
- sesamehr-0.1.0/src/sesamehr/autologin.py +118 -0
- sesamehr-0.1.0/src/sesamehr/bi.py +109 -0
- sesamehr-0.1.0/src/sesamehr/client.py +127 -0
- sesamehr-0.1.0/src/sesamehr/config.py +54 -0
- sesamehr-0.1.0/src/sesamehr/errors.py +79 -0
- sesamehr-0.1.0/src/sesamehr/http.py +119 -0
- sesamehr-0.1.0/src/sesamehr/modules/__init__.py +35 -0
- sesamehr-0.1.0/src/sesamehr/modules/announcements.py +38 -0
- sesamehr-0.1.0/src/sesamehr/modules/checks.py +372 -0
- sesamehr-0.1.0/src/sesamehr/modules/community.py +193 -0
- sesamehr-0.1.0/src/sesamehr/modules/contracts.py +140 -0
- sesamehr-0.1.0/src/sesamehr/modules/documents.py +91 -0
- sesamehr-0.1.0/src/sesamehr/modules/employees.py +283 -0
- sesamehr-0.1.0/src/sesamehr/modules/evaluations.py +87 -0
- sesamehr-0.1.0/src/sesamehr/modules/expenses.py +128 -0
- sesamehr-0.1.0/src/sesamehr/modules/job_charges.py +67 -0
- sesamehr-0.1.0/src/sesamehr/modules/notifications.py +34 -0
- sesamehr-0.1.0/src/sesamehr/modules/recruitment.py +81 -0
- sesamehr-0.1.0/src/sesamehr/modules/reports.py +42 -0
- sesamehr-0.1.0/src/sesamehr/modules/team.py +209 -0
- sesamehr-0.1.0/src/sesamehr/modules/vacations.py +249 -0
- sesamehr-0.1.0/src/sesamehr/modules/work_stats.py +59 -0
- sesamehr-0.1.0/src/sesamehr/py.typed +0 -0
- sesamehr-0.1.0/src/sesamehr/retry.py +59 -0
- sesamehr-0.1.0/src/sesamehr/types.py +33 -0
- sesamehr-0.1.0/tests/conftest.py +49 -0
- sesamehr-0.1.0/tests/test_auth.py +110 -0
- sesamehr-0.1.0/tests/test_bi.py +104 -0
- sesamehr-0.1.0/tests/test_checks.py +104 -0
- sesamehr-0.1.0/tests/test_community.py +134 -0
- sesamehr-0.1.0/tests/test_config.py +55 -0
- sesamehr-0.1.0/tests/test_employees.py +111 -0
- sesamehr-0.1.0/tests/test_errors.py +45 -0
- sesamehr-0.1.0/tests/test_http.py +123 -0
- sesamehr-0.1.0/tests/test_rest_modules.py +188 -0
- sesamehr-0.1.0/tests/test_retry.py +84 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Publishes sesamehr to PyPI when a GitHub Release is published.
|
|
4
|
+
# Uses PyPI Trusted Publishing (OIDC) — no API token stored. The matching
|
|
5
|
+
# trusted publisher on PyPI must be:
|
|
6
|
+
# Owner: SesameHR · Repository: sdk-python · Workflow: publish.yml · Environment: (none)
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
release:
|
|
10
|
+
types: [published]
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
id-token: write # required for PyPI trusted publishing
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
publish:
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v5
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: '3.12'
|
|
23
|
+
- name: Build distribution
|
|
24
|
+
run: |
|
|
25
|
+
pip install build
|
|
26
|
+
python -m build
|
|
27
|
+
- name: Publish to PyPI
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ['3.10', '3.11', '3.12', '3.13']
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v5
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- run: pip install -e . pytest
|
|
20
|
+
- run: pytest
|
sesamehr-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SesameHR
|
|
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.
|
sesamehr-0.1.0/PARITY.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# SDK Parity — TypeScript ↔ Python
|
|
2
|
+
|
|
3
|
+
This document records the parity audit between [`@sesamehr/sdk`](https://github.com/SesameHR/sdk)
|
|
4
|
+
(TypeScript, source of truth) and `sesamehr` (Python). The goal: the two SDKs are
|
|
5
|
+
**clones** — same modules, methods, endpoints, defaults, request bodies, BI queries,
|
|
6
|
+
and retry/error/header behavior — differing only in agreed language idioms.
|
|
7
|
+
|
|
8
|
+
Last audited: 2026-06-14, against TS SDK `0.5.0` / Python SDK `0.1.0`.
|
|
9
|
+
|
|
10
|
+
## Verdict
|
|
11
|
+
|
|
12
|
+
**Structural parity: confirmed.** Across the 15 modules + core (errors, retry, config,
|
|
13
|
+
http, bi, types, auth, autologin, client/exports):
|
|
14
|
+
|
|
15
|
+
| Dimension | Result |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| Public methods | 1:1 in every module (camelCase ↔ snake_case) |
|
|
18
|
+
| Endpoints (URL paths) | identical, char-for-char |
|
|
19
|
+
| HTTP methods | identical |
|
|
20
|
+
| Method-arg defaults (limit/offset/page/orderBy/…) | identical |
|
|
21
|
+
| Request body keys/values | identical |
|
|
22
|
+
| BI query construction (from/select/where/group_by/order_by) | identical |
|
|
23
|
+
| Retry policy (2 retries, 500 ms, 5xx + connection only) | identical |
|
|
24
|
+
| Headers (Authorization/CSID/ESID/x-company-id/X-Region) | identical |
|
|
25
|
+
| Public export surface | full parity (minus intentional idioms below) |
|
|
26
|
+
|
|
27
|
+
Verification: a 25-unit adversarial source audit (each divergence re-checked by an
|
|
28
|
+
independent verifier), a mechanical method/endpoint/default cross-check, the unit
|
|
29
|
+
suite (67 tests), and a read-only smoke test against the live API (34/35 endpoints;
|
|
30
|
+
the 35th is a server-side bug — see below).
|
|
31
|
+
|
|
32
|
+
## Method parity matrix
|
|
33
|
+
|
|
34
|
+
Every method exists on both sides (TS name ↔ Python name):
|
|
35
|
+
|
|
36
|
+
| Module | Methods |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| employees | list, working, on_break, remote, offline, search, by_department, by_office, by_job_charge, count, me |
|
|
39
|
+
| checks | history, today, this_week, this_month, remote_only, open_checks, hours_by_employee, hours_by_department, total_hours, my_requests, clock_in, clock_out, breaks, pause, request_create, request_edit, request_delete |
|
|
40
|
+
| vacations | calendars, balance_by_employee, history, by_type, pending_requests, requests_by_employee, request, cancel |
|
|
41
|
+
| work_stats | summary |
|
|
42
|
+
| evaluations | list, detail, results, my_evaluations, pending |
|
|
43
|
+
| documents | directory, list, upload, download_url |
|
|
44
|
+
| expenses | list, detail, categories, company_expenses |
|
|
45
|
+
| announcements | list, detail |
|
|
46
|
+
| job_charges | list, detail, employees |
|
|
47
|
+
| recruitment | vacancies, totals, vacancy, candidates |
|
|
48
|
+
| team | status, working, status_summary, employee_checks, check_requests, vacation_requests, create_check, edit_check, delete_check, approve_check_request, reject_check_request, approve_vacation, reject_vacation |
|
|
49
|
+
| reports | query |
|
|
50
|
+
| contracts | list, active, expiring_soon, by_type, status_summary |
|
|
51
|
+
| notifications | send_push |
|
|
52
|
+
| community | channels, posts, post, comments, create_post |
|
|
53
|
+
|
|
54
|
+
## Intentional language idioms (not divergences)
|
|
55
|
+
|
|
56
|
+
These are agreed Python idioms, applied consistently. They are the *only* expected
|
|
57
|
+
differences in how the surface looks:
|
|
58
|
+
|
|
59
|
+
1. **Naming**: methods and model fields are `snake_case` (TS `camelCase`). `workStats` → `work_stats`, `firstName` → `first_name`.
|
|
60
|
+
2. **Synchronous**: no `async`/`await`. Calls block.
|
|
61
|
+
3. **`timeout` in seconds** (TS uses milliseconds). Default 30.
|
|
62
|
+
4. **Keyword args instead of options objects**: TS `*Params` interfaces (`ListEmployeesParams`, `WorkStatsParams`, `RetryOptions`, …) become Python keyword arguments. Same inputs, no separate exported type. Date-range params `from`/`to` are positional (`from` is a reserved word).
|
|
63
|
+
5. **pydantic models instead of interfaces**: responses are validated models with `snake_case` attributes + camelCase aliases. Unknown API fields are preserved in `model_extra` (never dropped). Models are **permissive** — every field is optional — so validation never rejects data the TS `as T` cast would accept (see below).
|
|
64
|
+
6. **OAuth helpers omitted**: `configFromCredentials`, `SesameSDK.fromCredentials`, `SesameCredentials` are intentionally absent. Authenticate with a private token, `login()`, or `auto_login()`.
|
|
65
|
+
|
|
66
|
+
## Divergences found and fixed
|
|
67
|
+
|
|
68
|
+
The audit + smoke test surfaced these; all are now resolved in the Python SDK:
|
|
69
|
+
|
|
70
|
+
| Area | Was | Fix |
|
|
71
|
+
| --- | --- | --- |
|
|
72
|
+
| `expenses.list` / `company_expenses` | crashed — API returns `{data:{expenses,totals}, meta}`, not `Paginated` | modeled the real envelope as `ExpensePage` |
|
|
73
|
+
| `evaluations` models | `my_evaluations` crashed — API uses `evaluationId`, model required `id` | all id/title fields optional; added `evaluation_id` |
|
|
74
|
+
| Response models with required `id` | could reject sparse responses TS accepts | `id` made optional on all response models |
|
|
75
|
+
| retry timeout detection | case-insensitive + extra `'timed out'` substring → could skip a retry TS would do | aligned to TS exactly (case-sensitive, `'aborted'`/`'timeout'`); kept the robust `is_timeout` flag for genuine timeouts (same outcome as TS) |
|
|
76
|
+
| `BiOrderBy.direction` | empty-string `''` coerced to `'ASC'` | preserves `''` like TS `?? 'ASC'` |
|
|
77
|
+
| `_build_check_timestamp` | replaced only the first space with `T` | replaces all spaces, matching TS |
|
|
78
|
+
| `work_stats.summary` employee id | `or` truthiness (empty string fell through) | `is not None` check, matching TS `??` |
|
|
79
|
+
| `auth` login token check | extra `isinstance` guard | falsiness-only, matching TS |
|
|
80
|
+
| Public exports | `tenant_headers`, `default_should_retry` were public (TS keeps them internal) | removed from `__all__`; added `PermissionVisibilities`, `Reaction` to match TS |
|
|
81
|
+
|
|
82
|
+
## Divergences fixed on the TypeScript side
|
|
83
|
+
|
|
84
|
+
Three cases where the Python behavior was correct and the TS SDK had a latent bug.
|
|
85
|
+
**Both SDKs are now aligned** (TS changed to match the correct/real shape):
|
|
86
|
+
|
|
87
|
+
1. **Empty-body responses.** TS `doFetch` parsed the body unconditionally and threw on an empty `2xx` (e.g. a `204` from a DELETE). Now returns `undefined` on an empty body, matching Python's `None`.
|
|
88
|
+
2. **Expenses return type.** TS typed `expenses.list`/`companyExpenses` as `Paginated<Expense>`, which never matched the real API. Now returns `ExpensePage` (`{expenses, totals…, meta}`) — the same shape as the Python `ExpensePage`. **Breaking change for existing TS consumers** (the return type changed); ship behind a version bump.
|
|
89
|
+
3. **`Evaluation`.** TS declared `id: string` (required) and lacked `evaluationId`. Now every field is optional with an index signature, and `evaluationId`/`evaluationTitle`/`formTitle`/… are typed — matching the Python `Evaluation`.
|
|
90
|
+
|
|
91
|
+
TS suite after these fixes: 168 tests green.
|
|
92
|
+
|
|
93
|
+
## Not an SDK issue
|
|
94
|
+
|
|
95
|
+
- **`evaluations.list` → HTTP 500.** Deterministic on the QA account with `limit=5` (works with `limit=2`); a server-side serialization error on specific evaluation data. The TS SDK issues the identical request and fails identically. Tracked as a backend bug, not a parity gap.
|
sesamehr-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sesamehr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the Sesame HR API
|
|
5
|
+
Project-URL: Repository, https://github.com/SesameHR/sdk-python
|
|
6
|
+
Author: SesameHR
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: api,hr,human-resources,sdk,sesame,sesamehr,time-tracking
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Office/Business
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: httpx>=0.27
|
|
22
|
+
Requires-Dist: pydantic>=2.5
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# Sesame HR Python SDK
|
|
26
|
+
|
|
27
|
+
Official Python SDK for the [Sesame HR](https://www.sesamehr.com) API. Synchronous client built on `httpx` with `pydantic` models. Python port of [`@sesamehr/sdk`](https://github.com/SesameHR/sdk).
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install sesamehr
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Requires Python 3.10+.
|
|
36
|
+
|
|
37
|
+
## Quickstart
|
|
38
|
+
|
|
39
|
+
Authenticate with a private token — no OAuth required:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from sesamehr import SesameSDK
|
|
43
|
+
|
|
44
|
+
sdk = SesameSDK(
|
|
45
|
+
token="your-private-token",
|
|
46
|
+
region="EU1",
|
|
47
|
+
company_id="your-company-id",
|
|
48
|
+
employee_id="your-employee-id",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
for employee in sdk.employees.working():
|
|
52
|
+
print(employee.name, employee.work_status)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or login with email + password (same flow the SSO uses internally — no OAuth, no redirects):
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
sdk = SesameSDK.login("user@company.com", "****")
|
|
59
|
+
sdk.checks.clock_in()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The client holds an HTTP connection pool; use it as a context manager (or call `sdk.close()`) in long-running apps:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
with SesameSDK.login("user@company.com", "****") as sdk:
|
|
66
|
+
stats = sdk.work_stats.summary("2026-06-01", "2026-06-30")
|
|
67
|
+
print(stats.seconds_worked, stats.balance)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Modules
|
|
71
|
+
|
|
72
|
+
| Module | Description |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| `sdk.employees` | List/search employees, work status, counts, `me()` profile with roles & permissions |
|
|
75
|
+
| `sdk.checks` | Clock in/out, breaks, check history, hours aggregation, check requests |
|
|
76
|
+
| `sdk.vacations` | Calendars, balances, day-off history, requests |
|
|
77
|
+
| `sdk.work_stats` | Hours worked vs expected, balance, averages |
|
|
78
|
+
| `sdk.evaluations` | Performance evaluations and results |
|
|
79
|
+
| `sdk.documents` | Browse directories, list/upload/download documents |
|
|
80
|
+
| `sdk.expenses` | Personal and company expenses, categories |
|
|
81
|
+
| `sdk.announcements` | Company announcements |
|
|
82
|
+
| `sdk.job_charges` | Job positions and assigned employees |
|
|
83
|
+
| `sdk.recruitment` | Vacancies, totals, candidates |
|
|
84
|
+
| `sdk.team` | Team status, manage checks, approve/reject requests (admin) |
|
|
85
|
+
| `sdk.reports` | Raw BI queries against any Sesame BI table |
|
|
86
|
+
| `sdk.contracts` | Contracts, expirations, type/status breakdowns |
|
|
87
|
+
| `sdk.notifications` | Push notifications to the mobile app |
|
|
88
|
+
| `sdk.community` | Wall channels, posts and comments; publish posts |
|
|
89
|
+
|
|
90
|
+
All methods return pydantic models with snake_case attributes (the camelCase API fields are mapped automatically; unknown fields are kept in `model_extra`).
|
|
91
|
+
|
|
92
|
+
### Examples
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
# Check history for a date range (positional from/to)
|
|
96
|
+
entries = sdk.checks.history("2026-06-01", "2026-06-12", employee="ana")
|
|
97
|
+
|
|
98
|
+
# Vacation balance for the current year
|
|
99
|
+
balances = sdk.vacations.balance_by_employee()
|
|
100
|
+
|
|
101
|
+
# Raw BI query
|
|
102
|
+
from sesamehr import BI_TABLES, BI_TEMPORAL
|
|
103
|
+
|
|
104
|
+
rows = sdk.reports.query({
|
|
105
|
+
"from": BI_TABLES["checks"],
|
|
106
|
+
"select": [
|
|
107
|
+
{"field": "core_context_employee.name", "alias": "name"},
|
|
108
|
+
{"field": "schedule_context_check.seconds_worked", "aggregate": "SUM", "alias": "total"},
|
|
109
|
+
],
|
|
110
|
+
"where": [{"field": "schedule_context_check.date", "operation": BI_TEMPORAL["this_month"]}],
|
|
111
|
+
"group_by": ["core_context_employee.name"],
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
# Publish a post with an image to a community channel
|
|
115
|
+
with open("photo.png", "rb") as f:
|
|
116
|
+
sdk.community.create_post(
|
|
117
|
+
channel_id="...",
|
|
118
|
+
content="Hello from Python!",
|
|
119
|
+
file=f,
|
|
120
|
+
file_name="photo.png",
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Error handling
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from sesamehr import SesameApiError, SesameConnectionError
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
sdk.checks.clock_in()
|
|
131
|
+
except SesameApiError as e:
|
|
132
|
+
print(e.status, e.message, e.errors)
|
|
133
|
+
except SesameConnectionError as e:
|
|
134
|
+
print("network problem:", e)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Requests are retried automatically (2 retries, 500 ms delay) on connection errors and 5xx responses; 4xx responses and timeouts are not retried.
|
|
138
|
+
|
|
139
|
+
## Differences vs the TypeScript SDK
|
|
140
|
+
|
|
141
|
+
- Synchronous API (no `await`).
|
|
142
|
+
- Methods and fields are snake_case: `sdk.workStats.summary()` → `sdk.work_stats.summary()`, `employee.workStatus` → `employee.work_status`.
|
|
143
|
+
- `timeout` is in **seconds** (TS uses milliseconds). Default: 30.
|
|
144
|
+
- Date-range methods take `from`/`to` as positional arguments (`from` is a reserved word in Python): `sdk.checks.history("2026-06-01", "2026-06-12")`.
|
|
145
|
+
- OAuth helpers (`fromCredentials`) are not included — authenticate with a private token, `SesameSDK.login()`, or `SesameSDK.auto_login()`.
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
python -m venv .venv && source .venv/bin/activate
|
|
151
|
+
pip install -e . pytest
|
|
152
|
+
pytest
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
sesamehr-0.1.0/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Sesame HR Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for the [Sesame HR](https://www.sesamehr.com) API. Synchronous client built on `httpx` with `pydantic` models. Python port of [`@sesamehr/sdk`](https://github.com/SesameHR/sdk).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install sesamehr
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Python 3.10+.
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
Authenticate with a private token — no OAuth required:
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from sesamehr import SesameSDK
|
|
19
|
+
|
|
20
|
+
sdk = SesameSDK(
|
|
21
|
+
token="your-private-token",
|
|
22
|
+
region="EU1",
|
|
23
|
+
company_id="your-company-id",
|
|
24
|
+
employee_id="your-employee-id",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
for employee in sdk.employees.working():
|
|
28
|
+
print(employee.name, employee.work_status)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or login with email + password (same flow the SSO uses internally — no OAuth, no redirects):
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
sdk = SesameSDK.login("user@company.com", "****")
|
|
35
|
+
sdk.checks.clock_in()
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The client holds an HTTP connection pool; use it as a context manager (or call `sdk.close()`) in long-running apps:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
with SesameSDK.login("user@company.com", "****") as sdk:
|
|
42
|
+
stats = sdk.work_stats.summary("2026-06-01", "2026-06-30")
|
|
43
|
+
print(stats.seconds_worked, stats.balance)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Modules
|
|
47
|
+
|
|
48
|
+
| Module | Description |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `sdk.employees` | List/search employees, work status, counts, `me()` profile with roles & permissions |
|
|
51
|
+
| `sdk.checks` | Clock in/out, breaks, check history, hours aggregation, check requests |
|
|
52
|
+
| `sdk.vacations` | Calendars, balances, day-off history, requests |
|
|
53
|
+
| `sdk.work_stats` | Hours worked vs expected, balance, averages |
|
|
54
|
+
| `sdk.evaluations` | Performance evaluations and results |
|
|
55
|
+
| `sdk.documents` | Browse directories, list/upload/download documents |
|
|
56
|
+
| `sdk.expenses` | Personal and company expenses, categories |
|
|
57
|
+
| `sdk.announcements` | Company announcements |
|
|
58
|
+
| `sdk.job_charges` | Job positions and assigned employees |
|
|
59
|
+
| `sdk.recruitment` | Vacancies, totals, candidates |
|
|
60
|
+
| `sdk.team` | Team status, manage checks, approve/reject requests (admin) |
|
|
61
|
+
| `sdk.reports` | Raw BI queries against any Sesame BI table |
|
|
62
|
+
| `sdk.contracts` | Contracts, expirations, type/status breakdowns |
|
|
63
|
+
| `sdk.notifications` | Push notifications to the mobile app |
|
|
64
|
+
| `sdk.community` | Wall channels, posts and comments; publish posts |
|
|
65
|
+
|
|
66
|
+
All methods return pydantic models with snake_case attributes (the camelCase API fields are mapped automatically; unknown fields are kept in `model_extra`).
|
|
67
|
+
|
|
68
|
+
### Examples
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
# Check history for a date range (positional from/to)
|
|
72
|
+
entries = sdk.checks.history("2026-06-01", "2026-06-12", employee="ana")
|
|
73
|
+
|
|
74
|
+
# Vacation balance for the current year
|
|
75
|
+
balances = sdk.vacations.balance_by_employee()
|
|
76
|
+
|
|
77
|
+
# Raw BI query
|
|
78
|
+
from sesamehr import BI_TABLES, BI_TEMPORAL
|
|
79
|
+
|
|
80
|
+
rows = sdk.reports.query({
|
|
81
|
+
"from": BI_TABLES["checks"],
|
|
82
|
+
"select": [
|
|
83
|
+
{"field": "core_context_employee.name", "alias": "name"},
|
|
84
|
+
{"field": "schedule_context_check.seconds_worked", "aggregate": "SUM", "alias": "total"},
|
|
85
|
+
],
|
|
86
|
+
"where": [{"field": "schedule_context_check.date", "operation": BI_TEMPORAL["this_month"]}],
|
|
87
|
+
"group_by": ["core_context_employee.name"],
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
# Publish a post with an image to a community channel
|
|
91
|
+
with open("photo.png", "rb") as f:
|
|
92
|
+
sdk.community.create_post(
|
|
93
|
+
channel_id="...",
|
|
94
|
+
content="Hello from Python!",
|
|
95
|
+
file=f,
|
|
96
|
+
file_name="photo.png",
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Error handling
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from sesamehr import SesameApiError, SesameConnectionError
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
sdk.checks.clock_in()
|
|
107
|
+
except SesameApiError as e:
|
|
108
|
+
print(e.status, e.message, e.errors)
|
|
109
|
+
except SesameConnectionError as e:
|
|
110
|
+
print("network problem:", e)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Requests are retried automatically (2 retries, 500 ms delay) on connection errors and 5xx responses; 4xx responses and timeouts are not retried.
|
|
114
|
+
|
|
115
|
+
## Differences vs the TypeScript SDK
|
|
116
|
+
|
|
117
|
+
- Synchronous API (no `await`).
|
|
118
|
+
- Methods and fields are snake_case: `sdk.workStats.summary()` → `sdk.work_stats.summary()`, `employee.workStatus` → `employee.work_status`.
|
|
119
|
+
- `timeout` is in **seconds** (TS uses milliseconds). Default: 30.
|
|
120
|
+
- Date-range methods take `from`/`to` as positional arguments (`from` is a reserved word in Python): `sdk.checks.history("2026-06-01", "2026-06-12")`.
|
|
121
|
+
- OAuth helpers (`fromCredentials`) are not included — authenticate with a private token, `SesameSDK.login()`, or `SesameSDK.auto_login()`.
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
python -m venv .venv && source .venv/bin/activate
|
|
127
|
+
pip install -e . pytest
|
|
128
|
+
pytest
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
MIT
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sesamehr"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python SDK for the Sesame HR API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [{ name = "SesameHR" }]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"httpx>=0.27",
|
|
15
|
+
"pydantic>=2.5",
|
|
16
|
+
]
|
|
17
|
+
keywords = [
|
|
18
|
+
"sesame",
|
|
19
|
+
"sesamehr",
|
|
20
|
+
"hr",
|
|
21
|
+
"human-resources",
|
|
22
|
+
"api",
|
|
23
|
+
"sdk",
|
|
24
|
+
"time-tracking",
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 4 - Beta",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Office/Business",
|
|
36
|
+
"Topic :: Software Development :: Libraries",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Repository = "https://github.com/SesameHR/sdk-python"
|
|
41
|
+
|
|
42
|
+
[dependency-groups]
|
|
43
|
+
dev = ["pytest>=8"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/sesamehr"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Read-only smoke test against the real Sesame API.
|
|
2
|
+
|
|
3
|
+
Exercises every module's read endpoints and prints a pass/fail table. The point
|
|
4
|
+
is to validate that the *real* API response shapes parse into the pydantic
|
|
5
|
+
models — something the mocked unit tests can't catch.
|
|
6
|
+
|
|
7
|
+
NOTHING here mutates state: no clock-in/out, no post creation, no approvals.
|
|
8
|
+
|
|
9
|
+
Auth (pick one, via environment variables so secrets never hit the shell
|
|
10
|
+
history or this file):
|
|
11
|
+
|
|
12
|
+
# email + password (uses SesameSDK.login)
|
|
13
|
+
SESAME_EMAIL=you@company.com SESAME_PASSWORD='***' .venv/bin/python scripts/smoke.py
|
|
14
|
+
|
|
15
|
+
# or a private token you already have
|
|
16
|
+
SESAME_TOKEN=... SESAME_REGION=EU1 SESAME_COMPANY_ID=... SESAME_EMPLOYEE_ID=... \
|
|
17
|
+
.venv/bin/python scripts/smoke.py
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import os
|
|
23
|
+
import sys
|
|
24
|
+
import traceback
|
|
25
|
+
from datetime import date, timedelta
|
|
26
|
+
|
|
27
|
+
from sesamehr import SesameSDK
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def build_sdk() -> SesameSDK:
|
|
31
|
+
email = os.environ.get("SESAME_EMAIL")
|
|
32
|
+
password = os.environ.get("SESAME_PASSWORD")
|
|
33
|
+
if email and password:
|
|
34
|
+
print(f"→ Logging in as {email} (email + password)\n")
|
|
35
|
+
sdk = SesameSDK.login(email, password)
|
|
36
|
+
print(f" region={sdk.config.region} company={sdk.config.company_id} employee={sdk.config.employee_id}\n")
|
|
37
|
+
return sdk
|
|
38
|
+
|
|
39
|
+
token = os.environ.get("SESAME_TOKEN")
|
|
40
|
+
if token:
|
|
41
|
+
print("→ Using private token from env\n")
|
|
42
|
+
return SesameSDK(
|
|
43
|
+
token=token,
|
|
44
|
+
region=os.environ["SESAME_REGION"],
|
|
45
|
+
company_id=os.environ["SESAME_COMPANY_ID"],
|
|
46
|
+
employee_id=os.environ["SESAME_EMPLOYEE_ID"],
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
sys.exit(
|
|
50
|
+
"No credentials. Set SESAME_EMAIL + SESAME_PASSWORD, or "
|
|
51
|
+
"SESAME_TOKEN + SESAME_REGION + SESAME_COMPANY_ID + SESAME_EMPLOYEE_ID."
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def summarize(value: object) -> str:
|
|
56
|
+
"""One-line description of a result for the report."""
|
|
57
|
+
if isinstance(value, list):
|
|
58
|
+
return f"{len(value)} item(s)"
|
|
59
|
+
# Paginated / CommunityPage have a `.data` list and a `.meta`
|
|
60
|
+
data = getattr(value, "data", None)
|
|
61
|
+
if isinstance(data, list):
|
|
62
|
+
meta = getattr(value, "meta", None)
|
|
63
|
+
total = getattr(meta, "total", None)
|
|
64
|
+
suffix = f", total={total}" if total is not None else ""
|
|
65
|
+
return f"{len(data)} row(s){suffix}"
|
|
66
|
+
if value is None:
|
|
67
|
+
return "None"
|
|
68
|
+
# A single model — show a couple of identifying fields if present
|
|
69
|
+
for attr in ("id", "name", "work_status", "status"):
|
|
70
|
+
got = getattr(value, attr, None)
|
|
71
|
+
if got is not None:
|
|
72
|
+
return f"{type(value).__name__}({attr}={got!r})"
|
|
73
|
+
return type(value).__name__
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def main() -> int:
|
|
77
|
+
sdk = build_sdk()
|
|
78
|
+
|
|
79
|
+
today = date.today()
|
|
80
|
+
frm = (today - timedelta(days=30)).isoformat()
|
|
81
|
+
to = today.isoformat()
|
|
82
|
+
|
|
83
|
+
# (label, thunk) — every thunk is a pure read.
|
|
84
|
+
checks: list[tuple[str, object]] = [
|
|
85
|
+
("employees.me", lambda: sdk.employees.me()),
|
|
86
|
+
("employees.list", lambda: sdk.employees.list(limit=5)),
|
|
87
|
+
("employees.working", lambda: sdk.employees.working(limit=5)),
|
|
88
|
+
("employees.by_department", lambda: sdk.employees.by_department()),
|
|
89
|
+
("employees.count", lambda: sdk.employees.count()),
|
|
90
|
+
("checks.today", lambda: sdk.checks.today()),
|
|
91
|
+
("checks.this_month", lambda: sdk.checks.this_month()),
|
|
92
|
+
("checks.history", lambda: sdk.checks.history(frm, to, limit=5)),
|
|
93
|
+
("checks.breaks", lambda: sdk.checks.breaks()),
|
|
94
|
+
("checks.my_requests", lambda: sdk.checks.my_requests()),
|
|
95
|
+
("vacations.calendars", lambda: sdk.vacations.calendars(limit=5)),
|
|
96
|
+
("vacations.balance_by_employee", lambda: sdk.vacations.balance_by_employee(limit=5)),
|
|
97
|
+
("vacations.history", lambda: sdk.vacations.history(frm, to, limit=5)),
|
|
98
|
+
("vacations.pending_requests", lambda: sdk.vacations.pending_requests()),
|
|
99
|
+
("work_stats.summary", lambda: sdk.work_stats.summary(frm, to)),
|
|
100
|
+
("evaluations.list", lambda: sdk.evaluations.list(limit=5)),
|
|
101
|
+
("evaluations.my_evaluations", lambda: sdk.evaluations.my_evaluations(limit=5)),
|
|
102
|
+
("evaluations.pending", lambda: sdk.evaluations.pending()),
|
|
103
|
+
("documents.list", lambda: sdk.documents.list(limit=5)),
|
|
104
|
+
("expenses.list", lambda: sdk.expenses.list(limit=5)),
|
|
105
|
+
("expenses.categories", lambda: sdk.expenses.categories()),
|
|
106
|
+
("announcements.list", lambda: sdk.announcements.list(limit=5)),
|
|
107
|
+
("job_charges.list", lambda: sdk.job_charges.list(limit=5)),
|
|
108
|
+
("recruitment.vacancies", lambda: sdk.recruitment.vacancies(limit=5)),
|
|
109
|
+
("recruitment.totals", lambda: sdk.recruitment.totals()),
|
|
110
|
+
("team.status", lambda: sdk.team.status(limit=5)),
|
|
111
|
+
("team.status_summary", lambda: sdk.team.status_summary()),
|
|
112
|
+
("team.check_requests", lambda: sdk.team.check_requests()),
|
|
113
|
+
("team.vacation_requests", lambda: sdk.team.vacation_requests()),
|
|
114
|
+
("contracts.list", lambda: sdk.contracts.list(limit=5)),
|
|
115
|
+
("contracts.active", lambda: sdk.contracts.active(limit=5)),
|
|
116
|
+
("contracts.status_summary", lambda: sdk.contracts.status_summary()),
|
|
117
|
+
(
|
|
118
|
+
"reports.query",
|
|
119
|
+
lambda: sdk.reports.query(
|
|
120
|
+
{
|
|
121
|
+
"from": "core_context_employee",
|
|
122
|
+
"select": [{"field": "core_context_employee.name", "alias": "name"}],
|
|
123
|
+
"limit": 3,
|
|
124
|
+
}
|
|
125
|
+
),
|
|
126
|
+
),
|
|
127
|
+
("community.channels", lambda: sdk.community.channels(limit=5)),
|
|
128
|
+
("community.posts", lambda: sdk.community.posts(limit=5)),
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
width = max(len(label) for label, _ in checks)
|
|
132
|
+
passed = 0
|
|
133
|
+
failed: list[str] = []
|
|
134
|
+
|
|
135
|
+
for label, thunk in checks:
|
|
136
|
+
try:
|
|
137
|
+
result = thunk()
|
|
138
|
+
except Exception as exc: # noqa: BLE001 - we want every failure, not the first
|
|
139
|
+
failed.append(label)
|
|
140
|
+
print(f" ✗ {label:<{width}} {type(exc).__name__}: {exc}")
|
|
141
|
+
if os.environ.get("SMOKE_VERBOSE"):
|
|
142
|
+
traceback.print_exc()
|
|
143
|
+
else:
|
|
144
|
+
passed += 1
|
|
145
|
+
print(f" ✓ {label:<{width}} {summarize(result)}")
|
|
146
|
+
|
|
147
|
+
sdk.close()
|
|
148
|
+
|
|
149
|
+
print(f"\n{passed}/{len(checks)} read endpoints OK")
|
|
150
|
+
if failed:
|
|
151
|
+
print(f"Failed: {', '.join(failed)}")
|
|
152
|
+
print("Re-run with SMOKE_VERBOSE=1 for full tracebacks.")
|
|
153
|
+
return 1 if failed else 0
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
if __name__ == "__main__":
|
|
157
|
+
raise SystemExit(main())
|