mecanik-api 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.
@@ -0,0 +1,6 @@
1
+ """Official Python client for the Mecanik API."""
2
+
3
+ from .client import MecanikClient, MecanikError, Tools
4
+
5
+ __all__ = ["MecanikClient", "MecanikError", "Tools"]
6
+ __version__ = "1.0.0"
mecanik_api/client.py ADDED
@@ -0,0 +1,134 @@
1
+ """Official Python client for the Mecanik API.
2
+
3
+ from mecanik_api import MecanikClient
4
+
5
+ mecanik = MecanikClient(account_id="YOUR_UUID", token="YOUR_TOKEN")
6
+ result = mecanik.tools.security_headers(url="https://example.com")
7
+
8
+ Get your account UUID and an API token from https://members.mecanik.dev
9
+ (new accounts receive 100 free credits). Docs: https://api.mecanik.dev/docs
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from typing import Any, Dict, Optional
15
+
16
+ import requests
17
+
18
+ __all__ = ["MecanikClient", "MecanikError", "Tools"]
19
+
20
+
21
+ class MecanikError(Exception):
22
+ """Raised when an endpoint returns ``success: false`` or a non-2xx status."""
23
+
24
+ def __init__(self, message: str, status: int, errors: list[dict]):
25
+ super().__init__(message)
26
+ self.status = status
27
+ self.errors = errors
28
+
29
+
30
+ class MecanikClient:
31
+ def __init__(
32
+ self,
33
+ account_id: str,
34
+ token: str,
35
+ base_url: str = "https://api.mecanik.dev",
36
+ timeout: float = 30.0,
37
+ session: Optional[requests.Session] = None,
38
+ ):
39
+ if not account_id:
40
+ raise ValueError("account_id is required")
41
+ if not token:
42
+ raise ValueError("token is required")
43
+ self.account_id = account_id
44
+ self.token = token
45
+ self.base_url = base_url.rstrip("/")
46
+ self.timeout = timeout
47
+ self._session = session or requests.Session()
48
+ self.tools = Tools(self)
49
+
50
+ def raw(self, path: str, body: Optional[Dict[str, Any]] = None, method: str = "POST") -> Dict[str, Any]:
51
+ """Make a request and return the full ``{result, success, errors}`` envelope."""
52
+ url = f"{self.base_url}/v1/client/{self.account_id}{path}"
53
+ headers = {"Authorization": f"Bearer {self.token}"}
54
+ if method.upper() == "POST":
55
+ headers["Content-Type"] = "application/json"
56
+ resp = self._session.post(url, json=body or {}, headers=headers, timeout=self.timeout)
57
+ else:
58
+ resp = self._session.get(url, headers=headers, timeout=self.timeout)
59
+ try:
60
+ return resp.json()
61
+ except ValueError:
62
+ raise MecanikError(f"Invalid JSON response (HTTP {resp.status_code}).", resp.status_code, [])
63
+
64
+ def call(self, path: str, body: Optional[Dict[str, Any]] = None, method: str = "POST") -> Any:
65
+ """Call an endpoint and return just the ``result``; raises :class:`MecanikError` on failure."""
66
+ data = self.raw(path, body, method)
67
+ if not data.get("success"):
68
+ errors = data.get("errors") or []
69
+ first = errors[0] if errors else {}
70
+ raise MecanikError(first.get("message", "Request failed."), first.get("code", 0), errors)
71
+ return data.get("result")
72
+
73
+ def _tool(self, slug: str, body: Dict[str, Any]) -> Any:
74
+ return self.call(f"/tools/{slug}", body)
75
+
76
+ # Account
77
+ def account(self) -> Any:
78
+ return self.call("/account", method="GET")
79
+
80
+ def token_info(self) -> Any:
81
+ return self.call("/account/token", method="GET")
82
+
83
+ def credits(self) -> Any:
84
+ return self.call("/account/credits", method="GET")
85
+
86
+ def list_tools(self) -> Any:
87
+ return self.call("/tools", method="GET")
88
+
89
+
90
+ class Tools:
91
+ def __init__(self, client: MecanikClient):
92
+ self._c = client
93
+
94
+ # AI-Powered
95
+ def ai_code_review(self, **body: Any) -> Any: return self._c._tool("ai-code-review", body)
96
+ def ai_content_summarize(self, **body: Any) -> Any: return self._c._tool("ai-content-summarize", body)
97
+ def ai_seo_generate(self, **body: Any) -> Any: return self._c._tool("ai-seo-generate", body)
98
+ def ai_translate(self, **body: Any) -> Any: return self._c._tool("ai-translate", body)
99
+ def ai_chat(self, **body: Any) -> Any: return self._c._tool("ai-chat", body)
100
+ def ai_image_generate(self, **body: Any) -> Any: return self._c._tool("ai-image-generate", body)
101
+ def ai_extract(self, **body: Any) -> Any: return self._c._tool("ai-extract", body)
102
+ def ai_alt_text(self, **body: Any) -> Any: return self._c._tool("ai-alt-text", body)
103
+ def ai_moderation(self, **body: Any) -> Any: return self._c._tool("ai-moderation", body)
104
+
105
+ # Security & Website Analysis
106
+ def security_headers(self, **body: Any) -> Any: return self._c._tool("security-headers", body)
107
+ def tls_check(self, **body: Any) -> Any: return self._c._tool("tls-check", body)
108
+ def tech_detect(self, **body: Any) -> Any: return self._c._tool("tech-detect", body)
109
+ def seo_analyze(self, **body: Any) -> Any: return self._c._tool("seo-analyze", body)
110
+ def dns_lookup(self, **body: Any) -> Any: return self._c._tool("dns-lookup", body)
111
+ def openapi_validate(self, **body: Any) -> Any: return self._c._tool("openapi-validate", body)
112
+ def subdomain_finder(self, **body: Any) -> Any: return self._c._tool("subdomain-finder", body)
113
+ def exposed_files(self, **body: Any) -> Any: return self._c._tool("exposed-files", body)
114
+
115
+ # Email Tools
116
+ def email_deliverability(self, **body: Any) -> Any: return self._c._tool("email-deliverability", body)
117
+ def email_validator(self, **body: Any) -> Any: return self._c._tool("email-validator", body)
118
+ def email_validator_bulk(self, **body: Any) -> Any: return self._c._tool("email-validator-bulk", body)
119
+
120
+ # Premium Reports
121
+ def website_audit(self, **body: Any) -> Any: return self._c._tool("website-audit", body)
122
+ def performance_audit(self, **body: Any) -> Any: return self._c._tool("performance-audit", body)
123
+ def broken_link_checker(self, **body: Any) -> Any: return self._c._tool("broken-link-checker", body)
124
+ def carbon_footprint(self, **body: Any) -> Any: return self._c._tool("carbon-footprint", body)
125
+
126
+ # Developer Utilities
127
+ def qr_generate(self, **body: Any) -> Any: return self._c._tool("qr-generate", body)
128
+ def placeholder_image(self, query: str) -> Any: return self._c.call(f"/tools/placeholder-image?{query}", method="GET")
129
+ def hash_generate(self, **body: Any) -> Any: return self._c._tool("hash-generate", body)
130
+ def jwt_decode(self, **body: Any) -> Any: return self._c._tool("jwt-decode", body)
131
+ def password_strength(self, **body: Any) -> Any: return self._c._tool("password-strength", body)
132
+ def cron_explain(self, **body: Any) -> Any: return self._c._tool("cron-explain", body)
133
+ def token_counter(self, **body: Any) -> Any: return self._c._tool("token-counter", body)
134
+ def json_to_code(self, **body: Any) -> Any: return self._c._tool("json-to-code", body)
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: mecanik-api
3
+ Version: 1.0.0
4
+ Summary: Official Python client for the Mecanik API: AI, security analysis, email, reports and developer utility endpoints.
5
+ Author: Mecanik
6
+ License: MIT
7
+ Project-URL: Homepage, https://mecanik.dev/en/api/
8
+ Project-URL: Documentation, https://api.mecanik.dev/docs
9
+ Project-URL: Source, https://github.com/Mecanik-Dev/mecanik-sdk-python
10
+ Keywords: mecanik,api,sdk,security,ai,dns,seo,email-validation,developer-tools
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.25
15
+ Dynamic: license-file
16
+
17
+ # Mecanik API (Python)
18
+
19
+ Official Python client for the [Mecanik API](https://mecanik.dev/en/api/): AI, security analysis, email, reports and developer utility endpoints. Pay-per-use credits, no subscription.
20
+
21
+ **New accounts get 100 free credits.** Grab your account UUID and an API token at [members.mecanik.dev](https://members.mecanik.dev). Full reference: [api.mecanik.dev/docs](https://api.mecanik.dev/docs).
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pip install mecanik-api
27
+ ```
28
+
29
+ ## Quick start
30
+
31
+ ```python
32
+ from mecanik_api import MecanikClient
33
+
34
+ mecanik = MecanikClient(account_id="YOUR_ACCOUNT_UUID", token="YOUR_API_TOKEN")
35
+
36
+ # Each tool returns just the `result`, and raises MecanikError on failure.
37
+ headers = mecanik.tools.security_headers(url="https://example.com")
38
+ print(headers["grade"], headers["score"])
39
+
40
+ tokens = mecanik.tools.token_counter(text="Hello world", models=["gpt-4o", "claude-sonnet-4-6"])
41
+ audit = mecanik.tools.website_audit(url="https://example.com")
42
+ balance = mecanik.credits() # {"credits": ...}
43
+ ```
44
+
45
+ ## Error handling
46
+
47
+ ```python
48
+ from mecanik_api import MecanikError
49
+
50
+ try:
51
+ mecanik.tools.dns_lookup(domain="example.com")
52
+ except MecanikError as err:
53
+ print(err.status, str(err), err.errors)
54
+ # status 402 -> out of credits; 403 -> bad token; 429 -> rate limited
55
+ ```
56
+
57
+ ## Lower-level access
58
+
59
+ ```python
60
+ # Full envelope {"result", "success", "errors"}
61
+ res = mecanik.raw("/tools/dns-lookup", {"domain": "example.com"})
62
+
63
+ # Any endpoint by path
64
+ result = mecanik.call("/tools/hash-generate", {"input": "hello", "algorithm": "sha256"})
65
+ ```
66
+
67
+ ## Available tools
68
+
69
+ `mecanik.tools.*` provides one method per endpoint:
70
+
71
+ - **AI:** `ai_code_review`, `ai_content_summarize`, `ai_seo_generate`, `ai_translate`, `ai_chat`, `ai_image_generate`, `ai_extract`, `ai_alt_text`, `ai_moderation`
72
+ - **Security:** `security_headers`, `tls_check`, `tech_detect`, `seo_analyze`, `dns_lookup`, `openapi_validate`, `subdomain_finder`, `exposed_files`
73
+ - **Email:** `email_deliverability`, `email_validator`, `email_validator_bulk`
74
+ - **Reports:** `website_audit`, `performance_audit`, `broken_link_checker`, `carbon_footprint`
75
+ - **Utilities:** `qr_generate`, `placeholder_image`, `hash_generate`, `jwt_decode`, `password_strength`, `cron_explain`, `token_counter`, `json_to_code`
76
+
77
+ Account helpers: `account()`, `token_info()`, `credits()`, `list_tools()`.
78
+
79
+ The machine-readable spec is at [api.mecanik.dev/openapi.json](https://api.mecanik.dev/openapi.json).
80
+
81
+ ## License
82
+
83
+ MIT
@@ -0,0 +1,7 @@
1
+ mecanik_api/__init__.py,sha256=Nby05l6yYVNYJUU5kLibB0_CMrIeWt6vmB7S2EHo9IE,182
2
+ mecanik_api/client.py,sha256=QoDylXPfOWQkXmW0EA5Luc-fisBjt5Hcq9DOx7Xdccs,6478
3
+ mecanik_api-1.0.0.dist-info/licenses/LICENSE,sha256=bXoa7yEvJOJUauesqgPXq9A4EuYj4xRf0SBVXqn3ZKM,1072
4
+ mecanik_api-1.0.0.dist-info/METADATA,sha256=-IGO2c4i0cvgExHG4PNlvi3d0NoVvNbOcQlo6dyNzXU,3143
5
+ mecanik_api-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ mecanik_api-1.0.0.dist-info/top_level.txt,sha256=A6Z8oSU285fkY0Kn2onUkaZHixlv6ZDnds7EV5rIW7Q,12
7
+ mecanik_api-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MECANIK DEV LTD
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
+ mecanik_api