notiformer 1.0.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Notiformer
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,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: notiformer
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for Notiformer โ€” human-in-the-loop approval gates and push notifications for AI agents.
5
+ Author-email: Notiformer <hello@notiformer.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://notiformer.com
8
+ Project-URL: Documentation, https://notiformer.com/docs
9
+ Project-URL: Repository, https://github.com/notiformer/notiformer-python
10
+ Project-URL: Issues, https://github.com/notiformer/notiformer-python/issues
11
+ Keywords: notiformer,human-in-the-loop,ai-agents,approval,notifications,llm
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: requests>=2.25
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # notiformer (Python)
32
+
33
+ Official Python SDK for [Notiformer](https://notiformer.com) โ€” approval
34
+ gates, multi-option decisions, real-time push notifications, and feature
35
+ gates for AI agents. Mirrors the [Node.js SDK](https://www.npmjs.com/package/notiformer)
36
+ 1:1: same methods, same config, same REST API underneath.
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ pip install notiformer
42
+ ```
43
+
44
+ Requires Python 3.8+.
45
+
46
+ ## Get started
47
+
48
+ **1. Create a free account at [app.notiformer.com](https://app.notiformer.com)** โ€” no
49
+ credit card required for the Dev plan. Verify your email before creating a
50
+ project or using the API.
51
+
52
+ **2. Create a project and copy your API key** (`ntf_live_...`).
53
+
54
+ **3. Quick start:**
55
+
56
+ ```python
57
+ from notiformer import Notiformer
58
+
59
+ n = Notiformer("ntf_live_...")
60
+
61
+ # ๐Ÿ›‘ Pause and wait for Approve / Deny โ€” always set fallback or handle the raise
62
+ try:
63
+ result = n.ask(
64
+ "Deploy v2 to production?",
65
+ context="Build #442 ยท 3 services affected",
66
+ timeout=300,
67
+ fallback="deny", # omit and a timeout raises NotiformerError
68
+ )
69
+ if result["approved"]:
70
+ deploy()
71
+ else:
72
+ print("Timed out โ€” auto-denied" if result["timed_out"] else "Denied")
73
+ except NotiformerError as err:
74
+ if err.code == "timeout":
75
+ print("No response. Respond via the app, Telegram, or Slack.")
76
+
77
+ # ๐Ÿ”” Fire-and-forget alert
78
+ n.event("agents", "task_complete")
79
+ ```
80
+
81
+ Use `n = Notiformer("ntf_live_test")` to try the SDK without a real key โ€”
82
+ calls are skipped locally and safe defaults are returned (a one-time setup
83
+ notice is printed).
84
+
85
+ ## Config
86
+
87
+ ```python
88
+ Notiformer(
89
+ api_key,
90
+ *,
91
+ silent=False, # skip all calls locally, return safe defaults โ€” good for local/dev/test
92
+ throw_on_error=True, # False: event()/gate() failures return a default instead of raising
93
+ on_error=None, # callback: fn(NotiformerError) -> None, called on every failure
94
+ )
95
+ ```
96
+
97
+ > **`ask()`/`select()` always raise `NotiformerError(code="timeout")`** when
98
+ > nobody responds and no `fallback` was set โ€” this is unconditional and
99
+ > ignores `throw_on_error=False`. Set a `fallback`, or wrap the call in
100
+ > `try`/`except` and handle it explicitly.
101
+
102
+ ## API
103
+
104
+ ### `n.event(channel, event, *, description=None, icon=None, tags=None, value=None, notify=True, recipients=None)`
105
+
106
+ Fire-and-forget. Returns `{"id", "createdAt", "rateLimited"?, "usageMicroUsd"?}`,
107
+ or `None` if the placeholder key or `silent` is used, or the call failed
108
+ and `throw_on_error=False`.
109
+
110
+ ### `n.ask(message, *, timeout=300, fallback=None, context=None, details=None)`
111
+
112
+ Approval gate. Posts the request, then polls every 2s until it resolves.
113
+ Returns `{"approved", "timed_out", "responded_at"}`.
114
+
115
+ ### `n.select(message, options, *, timeout=300, fallback=None, context=None, details=None)`
116
+
117
+ Like `ask()`, but the user picks one of 2โ€“6 custom options instead of
118
+ Approve/Deny. Each option: `{"value", "label", "isDestructive"?}` โ€” use the
119
+ `select_option()` helper:
120
+
121
+ ```python
122
+ from notiformer import select_option
123
+ select_option("stop", "๐Ÿ›‘ Stop the pipeline", is_destructive=True)
124
+ ```
125
+
126
+ Returns `{"selected", "timed_out", "responded_at"}`.
127
+
128
+ ### `n.gate(key, *, fallback=False, cache_ttl=0)`
129
+
130
+ Boolean feature-gate check. **Never raises** โ€” always falls back on any
131
+ error. `cache_ttl` (seconds) enables a local in-memory cache on this client
132
+ instance only; there's no server-side caching.
133
+
134
+ ### `n.gate_details(key, *, fallback=False, cache_ttl=0)`
135
+
136
+ Same as `gate()`, returns `{"key", "enabled", "cached"}`.
137
+
138
+ ### `n.clear_gate_cache(key=None)`
139
+
140
+ Clears the local gate cache for one key, or all of them if omitted.
141
+
142
+ ## Errors
143
+
144
+ API and timeout failures raise `notiformer.NotiformerError`:
145
+
146
+ ```python
147
+ from notiformer import NotiformerError
148
+
149
+ try:
150
+ n.ask("Deploy?", timeout=60) # no fallback โ†’ raises on timeout
151
+ except NotiformerError as e:
152
+ print(e.code) # "timeout", "invalid_api_key", "rate_limited", "cap_reached", ...
153
+ raise
154
+ ```
155
+
156
+ `.code` is one of: `invalid_api_key`, `card_required`, `card_locked`,
157
+ `cap_reached`, `feature_not_available`, `validation`, `rate_limited`,
158
+ `network`, `internal`, `timeout`. On `cap_reached`, `.cycle_resets_at`,
159
+ `.manage_url`, and `.upgrade_url` may also be set.
160
+
161
+ Request-shape mistakes (missing `message`, wrong number of `options`, a
162
+ `fallback` that doesn't match any option, etc.) raise a plain `ValueError`
163
+ instead โ€” these are always raised, regardless of `throw_on_error`.
164
+
165
+ ## Links
166
+
167
+ - [Documentation](https://notiformer.com/docs)
168
+ - [Dashboard](https://app.notiformer.com)
169
+ - [Node.js SDK](https://www.npmjs.com/package/notiformer)
170
+ - Support: hello@notiformer.com
171
+
172
+ ## License
173
+
174
+ MIT
@@ -0,0 +1,144 @@
1
+ # notiformer (Python)
2
+
3
+ Official Python SDK for [Notiformer](https://notiformer.com) โ€” approval
4
+ gates, multi-option decisions, real-time push notifications, and feature
5
+ gates for AI agents. Mirrors the [Node.js SDK](https://www.npmjs.com/package/notiformer)
6
+ 1:1: same methods, same config, same REST API underneath.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pip install notiformer
12
+ ```
13
+
14
+ Requires Python 3.8+.
15
+
16
+ ## Get started
17
+
18
+ **1. Create a free account at [app.notiformer.com](https://app.notiformer.com)** โ€” no
19
+ credit card required for the Dev plan. Verify your email before creating a
20
+ project or using the API.
21
+
22
+ **2. Create a project and copy your API key** (`ntf_live_...`).
23
+
24
+ **3. Quick start:**
25
+
26
+ ```python
27
+ from notiformer import Notiformer
28
+
29
+ n = Notiformer("ntf_live_...")
30
+
31
+ # ๐Ÿ›‘ Pause and wait for Approve / Deny โ€” always set fallback or handle the raise
32
+ try:
33
+ result = n.ask(
34
+ "Deploy v2 to production?",
35
+ context="Build #442 ยท 3 services affected",
36
+ timeout=300,
37
+ fallback="deny", # omit and a timeout raises NotiformerError
38
+ )
39
+ if result["approved"]:
40
+ deploy()
41
+ else:
42
+ print("Timed out โ€” auto-denied" if result["timed_out"] else "Denied")
43
+ except NotiformerError as err:
44
+ if err.code == "timeout":
45
+ print("No response. Respond via the app, Telegram, or Slack.")
46
+
47
+ # ๐Ÿ”” Fire-and-forget alert
48
+ n.event("agents", "task_complete")
49
+ ```
50
+
51
+ Use `n = Notiformer("ntf_live_test")` to try the SDK without a real key โ€”
52
+ calls are skipped locally and safe defaults are returned (a one-time setup
53
+ notice is printed).
54
+
55
+ ## Config
56
+
57
+ ```python
58
+ Notiformer(
59
+ api_key,
60
+ *,
61
+ silent=False, # skip all calls locally, return safe defaults โ€” good for local/dev/test
62
+ throw_on_error=True, # False: event()/gate() failures return a default instead of raising
63
+ on_error=None, # callback: fn(NotiformerError) -> None, called on every failure
64
+ )
65
+ ```
66
+
67
+ > **`ask()`/`select()` always raise `NotiformerError(code="timeout")`** when
68
+ > nobody responds and no `fallback` was set โ€” this is unconditional and
69
+ > ignores `throw_on_error=False`. Set a `fallback`, or wrap the call in
70
+ > `try`/`except` and handle it explicitly.
71
+
72
+ ## API
73
+
74
+ ### `n.event(channel, event, *, description=None, icon=None, tags=None, value=None, notify=True, recipients=None)`
75
+
76
+ Fire-and-forget. Returns `{"id", "createdAt", "rateLimited"?, "usageMicroUsd"?}`,
77
+ or `None` if the placeholder key or `silent` is used, or the call failed
78
+ and `throw_on_error=False`.
79
+
80
+ ### `n.ask(message, *, timeout=300, fallback=None, context=None, details=None)`
81
+
82
+ Approval gate. Posts the request, then polls every 2s until it resolves.
83
+ Returns `{"approved", "timed_out", "responded_at"}`.
84
+
85
+ ### `n.select(message, options, *, timeout=300, fallback=None, context=None, details=None)`
86
+
87
+ Like `ask()`, but the user picks one of 2โ€“6 custom options instead of
88
+ Approve/Deny. Each option: `{"value", "label", "isDestructive"?}` โ€” use the
89
+ `select_option()` helper:
90
+
91
+ ```python
92
+ from notiformer import select_option
93
+ select_option("stop", "๐Ÿ›‘ Stop the pipeline", is_destructive=True)
94
+ ```
95
+
96
+ Returns `{"selected", "timed_out", "responded_at"}`.
97
+
98
+ ### `n.gate(key, *, fallback=False, cache_ttl=0)`
99
+
100
+ Boolean feature-gate check. **Never raises** โ€” always falls back on any
101
+ error. `cache_ttl` (seconds) enables a local in-memory cache on this client
102
+ instance only; there's no server-side caching.
103
+
104
+ ### `n.gate_details(key, *, fallback=False, cache_ttl=0)`
105
+
106
+ Same as `gate()`, returns `{"key", "enabled", "cached"}`.
107
+
108
+ ### `n.clear_gate_cache(key=None)`
109
+
110
+ Clears the local gate cache for one key, or all of them if omitted.
111
+
112
+ ## Errors
113
+
114
+ API and timeout failures raise `notiformer.NotiformerError`:
115
+
116
+ ```python
117
+ from notiformer import NotiformerError
118
+
119
+ try:
120
+ n.ask("Deploy?", timeout=60) # no fallback โ†’ raises on timeout
121
+ except NotiformerError as e:
122
+ print(e.code) # "timeout", "invalid_api_key", "rate_limited", "cap_reached", ...
123
+ raise
124
+ ```
125
+
126
+ `.code` is one of: `invalid_api_key`, `card_required`, `card_locked`,
127
+ `cap_reached`, `feature_not_available`, `validation`, `rate_limited`,
128
+ `network`, `internal`, `timeout`. On `cap_reached`, `.cycle_resets_at`,
129
+ `.manage_url`, and `.upgrade_url` may also be set.
130
+
131
+ Request-shape mistakes (missing `message`, wrong number of `options`, a
132
+ `fallback` that doesn't match any option, etc.) raise a plain `ValueError`
133
+ instead โ€” these are always raised, regardless of `throw_on_error`.
134
+
135
+ ## Links
136
+
137
+ - [Documentation](https://notiformer.com/docs)
138
+ - [Dashboard](https://app.notiformer.com)
139
+ - [Node.js SDK](https://www.npmjs.com/package/notiformer)
140
+ - Support: hello@notiformer.com
141
+
142
+ ## License
143
+
144
+ MIT
@@ -0,0 +1,46 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "notiformer"
7
+ version = "1.0.0"
8
+ description = "Official Python SDK for Notiformer โ€” human-in-the-loop approval gates and push notifications for AI agents."
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Notiformer", email = "hello@notiformer.com" }]
13
+ keywords = [
14
+ "notiformer",
15
+ "human-in-the-loop",
16
+ "ai-agents",
17
+ "approval",
18
+ "notifications",
19
+ "llm",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 4 - Beta",
23
+ "Intended Audience :: Developers",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Operating System :: OS Independent",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3.8",
28
+ "Programming Language :: Python :: 3.9",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Topic :: Software Development :: Libraries :: Python Modules",
33
+ ]
34
+ dependencies = ["requests>=2.25"]
35
+
36
+ [project.optional-dependencies]
37
+ dev = ["pytest>=7.0"]
38
+
39
+ [project.urls]
40
+ Homepage = "https://notiformer.com"
41
+ Documentation = "https://notiformer.com/docs"
42
+ Repository = "https://github.com/notiformer/notiformer-python"
43
+ Issues = "https://github.com/notiformer/notiformer-python/issues"
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,12 @@
1
+ from .client import Notiformer, select_option
2
+ from .exceptions import NotiformerError, NotiformerErrorCode
3
+
4
+ __version__ = "1.0.0"
5
+
6
+ __all__ = [
7
+ "Notiformer",
8
+ "select_option",
9
+ "NotiformerError",
10
+ "NotiformerErrorCode",
11
+ "__version__",
12
+ ]
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ import time
4
+ from typing import Dict, Optional, Tuple
5
+
6
+
7
+ class GateCache:
8
+ """Simple in-memory TTL cache for gate() values โ€” mirrors src/cache.ts.
9
+
10
+ Reduces API calls when gate() is called frequently for the same key.
11
+ Not shared across client instances or processes.
12
+ """
13
+
14
+ def __init__(self) -> None:
15
+ self._store: Dict[str, Tuple[bool, float]] = {} # key -> (value, expires_at)
16
+
17
+ def get(self, key: str) -> Optional[bool]:
18
+ entry = self._store.get(key)
19
+ if entry is None:
20
+ return None
21
+ value, expires_at = entry
22
+ if time.monotonic() > expires_at:
23
+ del self._store[key]
24
+ return None
25
+ return value
26
+
27
+ def set(self, key: str, value: bool, ttl_seconds: float) -> None:
28
+ if ttl_seconds <= 0:
29
+ return
30
+ self._store[key] = (value, time.monotonic() + ttl_seconds)
31
+
32
+ def delete(self, key: str) -> None:
33
+ self._store.pop(key, None)
34
+
35
+ def clear(self) -> None:
36
+ self._store.clear()
37
+
38
+ def size(self) -> int:
39
+ return len(self._store)