fraudlens 1.0.0__py3-none-any.whl
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.
fraudlens/__init__.py
ADDED
fraudlens/client.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""FraudLens antifraud server SDK — secret key (fk_sk_*) only."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import urllib.error
|
|
6
|
+
import urllib.parse
|
|
7
|
+
import urllib.request
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FrodError(Exception):
|
|
12
|
+
def __init__(self, message: str, *, status: int | None = None, code: str | None = None, body: Any = None):
|
|
13
|
+
super().__init__(message)
|
|
14
|
+
self.status = status
|
|
15
|
+
self.code = code
|
|
16
|
+
self.body = body
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Frod:
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
api_key: str | None = None,
|
|
23
|
+
*,
|
|
24
|
+
secret_key: str | None = None,
|
|
25
|
+
base_url: str = "https://fraudlens.io",
|
|
26
|
+
) -> None:
|
|
27
|
+
key = secret_key or api_key
|
|
28
|
+
if not key:
|
|
29
|
+
raise ValueError("secret_key (fk_sk_*) required")
|
|
30
|
+
if key.startswith("fk_pk_"):
|
|
31
|
+
raise ValueError("Publishable keys cannot call the server SDK — use the browser collect SDK")
|
|
32
|
+
self.api_key = key
|
|
33
|
+
self.base_url = base_url.rstrip("/")
|
|
34
|
+
|
|
35
|
+
def _req(
|
|
36
|
+
self,
|
|
37
|
+
method: str,
|
|
38
|
+
path: str,
|
|
39
|
+
body: dict | None = None,
|
|
40
|
+
*,
|
|
41
|
+
headers: dict[str, str] | None = None,
|
|
42
|
+
) -> dict[str, Any]:
|
|
43
|
+
data = None if body is None else json.dumps(body).encode("utf-8")
|
|
44
|
+
req = urllib.request.Request(
|
|
45
|
+
self.base_url + path,
|
|
46
|
+
data=data,
|
|
47
|
+
method=method,
|
|
48
|
+
headers={
|
|
49
|
+
"X-Api-Key": self.api_key,
|
|
50
|
+
"Accept": "application/json",
|
|
51
|
+
**({"Content-Type": "application/json"} if body is not None else {}),
|
|
52
|
+
**(headers or {}),
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
try:
|
|
56
|
+
with urllib.request.urlopen(req, timeout=30) as resp:
|
|
57
|
+
return json.loads(resp.read().decode("utf-8"))
|
|
58
|
+
except urllib.error.HTTPError as e:
|
|
59
|
+
payload = e.read().decode("utf-8", errors="ignore")
|
|
60
|
+
try:
|
|
61
|
+
parsed: Any = json.loads(payload)
|
|
62
|
+
except json.JSONDecodeError:
|
|
63
|
+
parsed = {"raw": payload}
|
|
64
|
+
err = (parsed or {}).get("error") if isinstance(parsed, dict) else None
|
|
65
|
+
raise FrodError(
|
|
66
|
+
(err or {}).get("message") if isinstance(err, dict) else str(parsed),
|
|
67
|
+
status=e.code,
|
|
68
|
+
code=(err or {}).get("code") if isinstance(err, dict) else None,
|
|
69
|
+
body=parsed,
|
|
70
|
+
) from e
|
|
71
|
+
|
|
72
|
+
def assess(self, *, idempotency_key: str | None = None, **kwargs: Any) -> dict[str, Any]:
|
|
73
|
+
headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
|
|
74
|
+
return self._req("POST", "/v1/assess", kwargs, headers=headers)
|
|
75
|
+
|
|
76
|
+
def email(self, address: str) -> dict[str, Any]:
|
|
77
|
+
return self._req("GET", "/v1/email/" + urllib.parse.quote(address))
|
|
78
|
+
|
|
79
|
+
def create_network_session(self, policy: str = "balanced") -> dict[str, Any]:
|
|
80
|
+
return self._req("POST", "/v1/network/sessions", {"policy": policy})
|
|
81
|
+
|
|
82
|
+
def network_session(self, session_id: str) -> dict[str, Any]:
|
|
83
|
+
return self._req("GET", "/v1/network/sessions/" + urllib.parse.quote(session_id))
|
|
84
|
+
|
|
85
|
+
def decision_policy(self) -> dict[str, Any]:
|
|
86
|
+
return self._req("GET", "/v1/account/decision-policy")
|
|
87
|
+
|
|
88
|
+
def set_decision_policy(self, **body: Any) -> dict[str, Any]:
|
|
89
|
+
return self._req("PUT", "/v1/account/decision-policy", body)
|
|
90
|
+
|
|
91
|
+
def health(self) -> dict[str, Any]:
|
|
92
|
+
return self._req("GET", "/v1/health")
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# Preferred alias
|
|
96
|
+
FraudLens = Frod
|
|
97
|
+
|
|
98
|
+
__all__ = ["Frod", "FraudLens", "FrodError"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fraudlens
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Thin Python server client for FraudLens API — secret key only
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://fraudlens.io
|
|
7
|
+
Project-URL: Documentation, https://fraudlens.io/docs/api/
|
|
8
|
+
Project-URL: Repository, https://github.com/fraudlens-io/fraudlens-python
|
|
9
|
+
Keywords: fraudlens,antifraud,email-reputation,signup-fraud
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# fraudlens (Python)
|
|
16
|
+
|
|
17
|
+
Thin **server** client for the [FraudLens](https://fraudlens.io) antifraud API (`fk_sk_*` only).
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install -e .
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from fraudlens import FraudLens
|
|
25
|
+
|
|
26
|
+
fl = FraudLens(secret_key="fk_sk_…")
|
|
27
|
+
res = fl.assess(
|
|
28
|
+
email="user@example.com",
|
|
29
|
+
session_id="ses_…",
|
|
30
|
+
user_id="merchant-user-1",
|
|
31
|
+
context={"flow": "signup"},
|
|
32
|
+
)
|
|
33
|
+
# res["score"] — higher = higher fraud risk
|
|
34
|
+
# res["action"] — allow | challenge | block (you enforce)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Hang browser collect first: [examples/hang](https://github.com/fraudlens-io/fraudlens-examples/tree/main/hang).
|
|
38
|
+
Full kit (OpenAPI, Postman, curl, Express): [fraudlens-examples](https://github.com/fraudlens-io/fraudlens-examples).
|
|
39
|
+
|
|
40
|
+
EmailRep migration: https://fraudlens.io/blog/migrate-from-emailrep.html
|
|
41
|
+
|
|
42
|
+
MIT · Proprietary scoring stays in FraudLens Cloud.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
fraudlens/__init__.py,sha256=c4RozP08XR3WD9CcHt95XoHnUARIFioJwOlVH95ohNY,153
|
|
2
|
+
fraudlens/client.py,sha256=uC7C6YJwIWNe7SjZdQQ1_DfywyJl7-5KutLg9Qejrcs,3600
|
|
3
|
+
fraudlens-1.0.0.dist-info/licenses/LICENSE,sha256=GAU4Uz7eHYNA6qCLMnXXg-0LHFIo3DtqPPVCXePlKUg,1087
|
|
4
|
+
fraudlens-1.0.0.dist-info/METADATA,sha256=zgNXy3lbW_mBQDK15DjaaEQFYQbg0o_oDYr-J6AJp9E,1368
|
|
5
|
+
fraudlens-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
fraudlens-1.0.0.dist-info/top_level.txt,sha256=UtTHPXbMC9pVa5UZnpBJVerurDMzdoSiy9eTm6znk8g,10
|
|
7
|
+
fraudlens-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FraudLens
|
|
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 @@
|
|
|
1
|
+
fraudlens
|