frappex-client 0.1.1__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.
Files changed (31) hide show
  1. frappex_client-0.1.1/.gitignore +15 -0
  2. frappex_client-0.1.1/CHANGELOG.md +57 -0
  3. frappex_client-0.1.1/LICENSE +21 -0
  4. frappex_client-0.1.1/PKG-INFO +382 -0
  5. frappex_client-0.1.1/README.md +353 -0
  6. frappex_client-0.1.1/SECURITY.md +45 -0
  7. frappex_client-0.1.1/docs/DEVELOPMENT.md +204 -0
  8. frappex_client-0.1.1/docs/PRD.md +161 -0
  9. frappex_client-0.1.1/pyproject.toml +98 -0
  10. frappex_client-0.1.1/src/frappex_client/__init__.py +60 -0
  11. frappex_client-0.1.1/src/frappex_client/_async_client.py +442 -0
  12. frappex_client-0.1.1/src/frappex_client/_auth.py +116 -0
  13. frappex_client-0.1.1/src/frappex_client/_base.py +162 -0
  14. frappex_client-0.1.1/src/frappex_client/_client.py +437 -0
  15. frappex_client-0.1.1/src/frappex_client/_config.py +147 -0
  16. frappex_client-0.1.1/src/frappex_client/_operations.py +251 -0
  17. frappex_client-0.1.1/src/frappex_client/_protocol.py +248 -0
  18. frappex_client-0.1.1/src/frappex_client/exceptions.py +138 -0
  19. frappex_client-0.1.1/src/frappex_client/py.typed +0 -0
  20. frappex_client-0.1.1/src/frappex_client/types.py +17 -0
  21. frappex_client-0.1.1/tests/__init__.py +0 -0
  22. frappex_client-0.1.1/tests/integration/__init__.py +0 -0
  23. frappex_client-0.1.1/tests/integration/conftest.py +105 -0
  24. frappex_client-0.1.1/tests/integration/test_documents.py +146 -0
  25. frappex_client-0.1.1/tests/integration/test_methods_files_auth.py +188 -0
  26. frappex_client-0.1.1/tests/unit/__init__.py +0 -0
  27. frappex_client-0.1.1/tests/unit/conftest.py +81 -0
  28. frappex_client-0.1.1/tests/unit/test_clients.py +373 -0
  29. frappex_client-0.1.1/tests/unit/test_operations.py +105 -0
  30. frappex_client-0.1.1/tests/unit/test_pure.py +269 -0
  31. frappex_client-0.1.1/tests/unit/test_security.py +257 -0
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .mypy_cache/
8
+ .ruff_cache/
9
+ .pytest_cache/
10
+ .coverage
11
+ htmlcov/
12
+ .env
13
+ .env.*
14
+ .uv-cache/
15
+ requirements-audit.txt
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes are recorded here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.1] - 2026-11-24
10
+
11
+ ### Changed
12
+
13
+ - **Renamed to `frappex-client`.** Install with `pip install frappex-client`
14
+ and import `frappex_client`. The name `frappix` already belongs to an
15
+ established Frappe community project by another author (Frappe on Nix), so
16
+ this library no longer uses it. There are no other changes to the API.
17
+ - The base exception is now `FrappexError` (was `FrappixError`).
18
+ - Integration test settings are now `FRAPPEX_TEST_*` (were `FRAPPIX_TEST_*`).
19
+ - Documentation moved to <https://frappex-client.zeal.ninja>.
20
+
21
+ ### Migrating from frappix 0.1.0
22
+
23
+ ```bash
24
+ pip uninstall frappix
25
+ pip install frappex-client
26
+ ```
27
+
28
+ Then replace `frappix` with `frappex_client` in imports and `FrappixError`
29
+ with `FrappexError`. The `frappix` 0.1.0 release on PyPI is yanked.
30
+
31
+ ## [0.1.0] - 2026-11-24
32
+
33
+ First release, published under the name `frappix`.
34
+
35
+ ### Added
36
+
37
+ - `Client` and `AsyncClient` with document, method, file and pagination calls.
38
+ - `TokenAuth`, `BearerAuth` and `PasswordAuth`.
39
+ - Guest access: `auth` is optional, for `ping`, public files and
40
+ `allow_guest` methods.
41
+ - Typed exception hierarchy and `RetryPolicy`.
42
+ - Unit tests for both clients and an integration suite for a live site,
43
+ run in CI against Frappe 14, 15 and 16.
44
+ - Property-based security tests, coverage threshold, and CI security
45
+ scanning (CodeQL, Semgrep, Gitleaks, pip-audit, zizmor, Scorecard).
46
+
47
+ ### Fixed
48
+
49
+ - `get_value` returns `None`, not an empty mapping, when nothing matches.
50
+ - An error reply containing an unpaired surrogate no longer crashes decoding.
51
+ - An unsupported `verify` value raises `ConfigurationError`.
52
+ - `exc_type` is read from Frappe 14's `exception` field when `exc_type` is
53
+ absent.
54
+
55
+ [Unreleased]: https://github.com/Padmapriyan27/frappex-client/compare/v0.1.1...HEAD
56
+ [0.1.1]: https://github.com/Padmapriyan27/frappex-client/compare/v0.1.0...v0.1.1
57
+ [0.1.0]: https://github.com/Padmapriyan27/frappex-client/releases/tag/v0.1.0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The frappex-client authors
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.
@@ -0,0 +1,382 @@
1
+ Metadata-Version: 2.5
2
+ Name: frappex-client
3
+ Version: 0.1.1
4
+ Summary: Typed sync and async REST client for Frappe and ERPNext sites.
5
+ Project-URL: Homepage, https://github.com/Padmapriyan27/frappex-client
6
+ Project-URL: Documentation, https://frappex-client.zeal.ninja
7
+ Project-URL: Repository, https://github.com/Padmapriyan27/frappex-client
8
+ Project-URL: Issues, https://github.com/Padmapriyan27/frappex-client/issues
9
+ Project-URL: Changelog, https://github.com/Padmapriyan27/frappex-client/blob/main/CHANGELOG.md
10
+ Project-URL: Security, https://github.com/Padmapriyan27/frappex-client/security/policy
11
+ Author: Padmapriyan N
12
+ Maintainer: Padmapriyan N
13
+ License-Expression: MIT
14
+ License-File: LICENSE
15
+ Keywords: async,client,erpnext,frappe,httpx,rest
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
24
+ Classifier: Topic :: Internet :: WWW/HTTP
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: httpx<1,>=0.27
28
+ Description-Content-Type: text/markdown
29
+
30
+ # frappex-client
31
+
32
+ [![CI](https://github.com/Padmapriyan27/frappex-client/actions/workflows/ci.yml/badge.svg)](https://github.com/Padmapriyan27/frappex-client/actions/workflows/ci.yml)
33
+ [![Integration](https://github.com/Padmapriyan27/frappex-client/actions/workflows/integration.yml/badge.svg)](https://github.com/Padmapriyan27/frappex-client/actions/workflows/integration.yml)
34
+ [![Security](https://github.com/Padmapriyan27/frappex-client/actions/workflows/security.yml/badge.svg)](https://github.com/Padmapriyan27/frappex-client/actions/workflows/security.yml)
35
+ [![CodeQL](https://github.com/Padmapriyan27/frappex-client/actions/workflows/codeql.yml/badge.svg)](https://github.com/Padmapriyan27/frappex-client/actions/workflows/codeql.yml)
36
+ [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/Padmapriyan27/frappex-client/badge)](https://scorecard.dev/viewer/?uri=github.com/Padmapriyan27/frappex-client)
37
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
38
+
39
+ A typed REST client for [Frappe](https://frappe.io/framework) and ERPNext sites,
40
+ with a blocking client and an `asyncio` client that share one implementation.
41
+
42
+ **Documentation: <https://frappex-client.zeal.ninja>**: guides, recipes and the full API reference.
43
+
44
+ frappex-client is an independent community project. It is not affiliated with or
45
+ endorsed by Frappe Technologies.
46
+
47
+ ## What it is
48
+
49
+ Every Frappe and ERPNext site has a REST API: any program can read and write
50
+ its documents over HTTP. frappex-client is the Python package for the other end of
51
+ that connection, the code that runs **outside** the site and talks to it.
52
+
53
+ Instead of building URLs, encoding filters as JSON and decoding Frappe's error
54
+ format by hand:
55
+
56
+ ```python
57
+ import json
58
+
59
+ import requests
60
+
61
+ response = requests.get(
62
+ "https://erp.example.com/api/resource/Customer",
63
+ headers={"Authorization": f"token {key}:{secret}"},
64
+ params={
65
+ "filters": json.dumps({"territory": "India"}),
66
+ "fields": json.dumps(["name", "customer_name"]),
67
+ "limit_page_length": 20,
68
+ },
69
+ timeout=30,
70
+ )
71
+ response.raise_for_status()
72
+ customers = response.json()["data"]
73
+ ```
74
+
75
+ you write:
76
+
77
+ ```python
78
+ customers = client.get_list(
79
+ "Customer", filters={"territory": "India"}, fields=["name", "customer_name"]
80
+ )
81
+ ```
82
+
83
+ ## Why frappex-client
84
+
85
+ Frappe publishes no maintained Python client on PyPI. The official
86
+ `frappe-client` repository is archived and was never published, so most
87
+ projects either install an unmaintained package or write raw HTTP calls and
88
+ solve the same problems again:
89
+
90
+ | Problem with hand-written calls | What frappex-client does |
91
+ |---|---|
92
+ | No `asyncio` support for FastAPI, bots and other async programs | `AsyncClient` with the same methods as `Client` |
93
+ | The API returns 20 rows by default; reading everything needs a loop | `iter_list` walks every page in a stable order |
94
+ | Errors arrive as Frappe's own JSON and must be decoded | A typed exception per failure: `NotFoundError`, `PermissionDeniedError`, `ValidationError` and more |
95
+ | A retried insert can create a duplicate document | Only safe requests are retried; writes never are |
96
+ | TLS checks get switched off and keys end up in logs | HTTPS only, certificate checks always on, secrets masked everywhere |
97
+ | No editor help | Fully typed, checked with `mypy --strict` |
98
+
99
+ It has one dependency (`httpx`) and is tested on every change against real
100
+ Frappe 14, 15 and 16 sites.
101
+
102
+ ## Use cases
103
+
104
+ **Sync another system into ERPNext.** A webshop, CRM or form backend that
105
+ creates or updates ERPNext records:
106
+
107
+ ```python
108
+ import os
109
+
110
+ from frappex_client import Client, TokenAuth
111
+
112
+ erp = Client(os.environ["ERP_URL"], TokenAuth(os.environ["ERP_KEY"], os.environ["ERP_SECRET"]))
113
+
114
+
115
+ def upsert_customer(email: str, values: dict[str, str]) -> None:
116
+ existing = erp.get_value("Customer", "name", {"email_id": email})
117
+ if existing:
118
+ erp.update("Customer", existing["name"], values)
119
+ else:
120
+ erp.insert("Customer", {"email_id": email, **values})
121
+ ```
122
+
123
+ **Serve ERP data from an async web app.** One shared `AsyncClient` in a
124
+ FastAPI service:
125
+
126
+ ```python
127
+ from contextlib import asynccontextmanager
128
+
129
+ from fastapi import FastAPI
130
+
131
+ from frappex_client import AsyncClient, TokenAuth
132
+
133
+
134
+ @asynccontextmanager
135
+ async def lifespan(app: FastAPI):
136
+ async with AsyncClient("https://erp.example.com", TokenAuth("key", "secret")) as erp:
137
+ app.state.erp = erp
138
+ yield
139
+
140
+
141
+ app = FastAPI(lifespan=lifespan)
142
+
143
+
144
+ @app.get("/orders/{name}")
145
+ async def order(name: str):
146
+ return await app.state.erp.get_doc("Sales Order", name)
147
+ ```
148
+
149
+ **Export data for reports and pipelines.** Every row, without writing a
150
+ pagination loop:
151
+
152
+ ```python
153
+ import csv
154
+
155
+ fields = ["name", "customer_name", "territory"]
156
+ with open("customers.csv", "w", newline="") as out:
157
+ writer = csv.DictWriter(out, fieldnames=fields)
158
+ writer.writeheader()
159
+ writer.writerows(erp.iter_list("Customer", fields=fields))
160
+ ```
161
+
162
+ **Call your own app's API.** Methods you whitelist in a custom Frappe app,
163
+ from scripts, bots or other services:
164
+
165
+ ```python
166
+ summary = erp.call("myapp.api.monthly_summary", {"year": 2026}, http_method="GET")
167
+ ```
168
+
169
+ **Attach files to documents.** Invoices, scans and reports, private by
170
+ default:
171
+
172
+ ```python
173
+ with open("invoice.pdf", "rb") as pdf:
174
+ erp.upload_file("invoice.pdf", pdf.read(), doctype="Sales Invoice", docname="SINV-0001")
175
+ ```
176
+
177
+ **Monitor a site.** A health check needs no credentials:
178
+
179
+ ```python
180
+ from frappex_client import Client, FrappexError
181
+
182
+ try:
183
+ with Client("https://erp.example.com", timeout=5) as site:
184
+ healthy = site.ping() == "pong"
185
+ except FrappexError:
186
+ healthy = False
187
+ ```
188
+
189
+ ### When not to use it
190
+
191
+ - **Code running inside a Frappe app.** Use `frappe.get_doc` and the rest of
192
+ the server-side API directly; there is no need to go over HTTP.
193
+ - **Realtime events, reports or print formats.** frappex-client covers documents,
194
+ whitelisted methods and files. Call a report or print method with `call`.
195
+ - **The `/api/v2` routes.** Planned for a later release.
196
+
197
+ ## Features
198
+
199
+ - Sync (`Client`) and async (`AsyncClient`) with identical methods
200
+ - API key, OAuth bearer token, username/password, or guest access
201
+ - Automatic pagination with `iter_list`
202
+ - A typed exception for each kind of failure
203
+ - Retries only where repeating a request is safe
204
+ - Secure defaults: HTTPS only, certificate checks always on, no redirects
205
+ followed, credentials never printed
206
+ - Fully type-annotated; one dependency (`httpx`)
207
+
208
+ Requires Python 3.10+. Uses the `/api/resource` and `/api/method` routes.
209
+ The integration suite runs in CI against Frappe v14, v15 and v16.
210
+
211
+ ## Install
212
+
213
+ ```bash
214
+ pip install frappex-client
215
+ ```
216
+
217
+ ## Quick start
218
+
219
+ ```python
220
+ from frappex_client import Client, TokenAuth
221
+
222
+ with Client("https://erp.example.com", TokenAuth("api_key", "api_secret")) as client:
223
+ print(client.get_logged_user())
224
+
225
+ todo = client.insert("ToDo", {"description": "Call the supplier"})
226
+ client.update("ToDo", todo["name"], {"status": "Closed"})
227
+
228
+ for row in client.iter_list("ToDo", fields=["name", "status"], filters={"status": "Open"}):
229
+ print(row["name"])
230
+ ```
231
+
232
+ The async client is the same, awaited:
233
+
234
+ ```python
235
+ import asyncio
236
+ from frappex_client import AsyncClient, TokenAuth
237
+
238
+
239
+ async def main() -> None:
240
+ async with AsyncClient("https://erp.example.com", TokenAuth("key", "secret")) as client:
241
+ async for row in client.iter_list("Customer", fields=["name"]):
242
+ print(row["name"])
243
+
244
+
245
+ asyncio.run(main())
246
+ ```
247
+
248
+ ## Authentication
249
+
250
+ | Class | Use it for |
251
+ |---|---|
252
+ | `TokenAuth(api_key, api_secret)` | Servers, scripts and jobs. Recommended. |
253
+ | `BearerAuth(token)` | An OAuth 2 access token issued by the site. |
254
+ | `PasswordAuth(username, password)` | A cookie session. Logs in on first use, logs out on close. |
255
+ | *(omitted)* | Guest access. No credentials are sent. |
256
+
257
+ Read credentials from the environment or a secret store, never from source code.
258
+
259
+ Without `auth`, the client acts as a guest. That is enough for a health check,
260
+ public files and methods the site whitelists with `allow_guest`:
261
+
262
+ ```python
263
+ from frappex_client import Client
264
+
265
+ with Client("https://erp.example.com") as client:
266
+ assert client.ping() == "pong"
267
+ ```
268
+
269
+ ## Methods
270
+
271
+ | Method | What it does |
272
+ |---|---|
273
+ | `ping()` | Check the site answers. |
274
+ | `get_logged_user()` | Return the authenticated user. |
275
+ | `get_list(doctype, fields=, filters=, or_filters=, order_by=, limit=, offset=)` | One page of documents. |
276
+ | `iter_list(doctype, ..., page_size=)` | Every matching document, page by page. |
277
+ | `get_doc(doctype, name)` | One document. |
278
+ | `insert(doctype, values)` | Create a document. |
279
+ | `update(doctype, name, values)` | Change fields. |
280
+ | `delete(doctype, name)` | Delete a document. |
281
+ | `submit(doctype, name)` / `cancel(doctype, name)` | Submit or cancel. |
282
+ | `rename(doctype, old_name, new_name, merge=)` | Rename; returns the new name. |
283
+ | `get_count(doctype, filters)` | Count matching documents. |
284
+ | `get_value(doctype, fieldname, filters)` / `set_value(doctype, name, values)` | Read or set fields. |
285
+ | `call(method, params, http_method=)` | Call a whitelisted method. |
286
+ | `upload_file(filename, content, is_private=, doctype=, docname=)` | Upload a file. |
287
+ | `download(file_url)` / `download_to(file_url, target)` | Fetch a file. |
288
+
289
+ ## Errors
290
+
291
+ ```python
292
+ from frappex_client import NotFoundError, PermissionDeniedError, ValidationError, FrappexError
293
+
294
+ try:
295
+ client.get_doc("Customer", "CUST-0001")
296
+ except NotFoundError:
297
+ ...
298
+ except PermissionDeniedError:
299
+ ...
300
+ except FrappexError as error: # everything frappex-client raises
301
+ ...
302
+ ```
303
+
304
+ | Exception | When |
305
+ |---|---|
306
+ | `AuthenticationError` | 401: bad or expired credentials |
307
+ | `PermissionDeniedError` | 403 |
308
+ | `NotFoundError` | 404 |
309
+ | `ConflictError` | 409: duplicate or conflicting write |
310
+ | `ValidationError` | 417 and other 4xx |
311
+ | `RateLimitError` | 429; `retry_after` holds the advised wait |
312
+ | `ServerError` | 5xx |
313
+ | `TransportError`, `RequestTimeoutError` | No response was received |
314
+ | `UnexpectedResponseError` | Redirect or non-JSON reply (usually a wrong `base_url`) |
315
+ | `ResponseTooLargeError` | Body above `max_response_bytes` |
316
+ | `ConfigurationError` | An unsafe or malformed argument |
317
+
318
+ `APIError` subclasses carry `status_code`, `exc_type`, `server_messages` and
319
+ `traceback`. Frappe 14 does not always report the exception type, so
320
+ `exc_type` can be `None` there; rely on the exception class instead. The server traceback is deliberately left out of `str(error)`.
321
+
322
+ ## Security behaviour
323
+
324
+ - `http://` is refused unless you pass `allow_insecure_http=True` (local development only).
325
+ - TLS verification cannot be disabled. For a private CA, pass `verify="/path/ca.pem"` or an `ssl.SSLContext`.
326
+ - Redirects are never followed, so credentials cannot be forwarded to another host.
327
+ - DocType and document names are percent-encoded; `.` and `..` are rejected.
328
+ - `download` accepts only site-relative paths.
329
+ - Uploads are private by default.
330
+ - Writes are never retried after a network error or 5xx. `GET` requests and HTTP 429 replies are.
331
+ - Secrets are masked in `repr()` and never logged.
332
+
333
+ See [SECURITY.md](SECURITY.md) to report a vulnerability.
334
+
335
+ ## Retries and timeouts
336
+
337
+ ```python
338
+ from frappex_client import Client, RetryPolicy, TokenAuth
339
+
340
+ client = Client(
341
+ "https://erp.example.com",
342
+ TokenAuth("key", "secret"),
343
+ timeout=10,
344
+ retry=RetryPolicy(max_attempts=5, backoff_base=1.0),
345
+ )
346
+ ```
347
+
348
+ `RetryPolicy(max_attempts=1)` turns retries off.
349
+
350
+ ## Development
351
+
352
+ ```bash
353
+ uv sync
354
+ uv run ruff check . && uv run ruff format --check .
355
+ uv run mypy
356
+ uv run pytest
357
+ ```
358
+
359
+ Integration tests run against a live development site and are skipped unless
360
+ these are set. They remove everything they create. See the
361
+ [developer guide](docs/DEVELOPMENT.md#integration-tests) for the full list of
362
+ settings and the permissions the API user needs:
363
+
364
+ ```bash
365
+ export FRAPPEX_TEST_URL=http://localhost:8000
366
+ export FRAPPEX_TEST_API_KEY=...
367
+ export FRAPPEX_TEST_API_SECRET=...
368
+ uv run pytest -m integration
369
+ ```
370
+
371
+ ## Documentation
372
+
373
+ - [Documentation website](https://frappex-client.zeal.ninja): guides, recipes and the API reference
374
+ - [Developer guide](docs/DEVELOPMENT.md): architecture, adding a call, tests, releasing
375
+ - [Product requirements](docs/PRD.md): goals, scope and requirements
376
+ - [Security policy](SECURITY.md)
377
+ - [Contributing](CONTRIBUTING.md)
378
+ - [Changelog](CHANGELOG.md)
379
+
380
+ ## License
381
+
382
+ MIT