botversion-sdk 2.2.3__tar.gz → 2.3.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 (95) hide show
  1. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/PKG-INFO +34 -2
  2. botversion_sdk-2.3.1/README.md +23 -0
  3. botversion_sdk-2.3.1/botversion_sdk/__init__.py +19 -0
  4. {botversion_sdk-2.2.3/botversion_sdk → botversion_sdk-2.3.1/botversion_sdk/scanner_sdk}/__init__.py +1 -3
  5. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/bin/__init__.py +1 -0
  6. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/bin/scan_endpoints.py +114 -0
  7. {botversion_sdk-2.2.3/botversion_sdk → botversion_sdk-2.3.1/botversion_sdk/scanner_sdk}/client.py +1 -1
  8. {botversion_sdk-2.2.3/botversion_sdk → botversion_sdk-2.3.1/botversion_sdk/scanner_sdk}/interceptor.py +3 -3
  9. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/__init__.py +2 -0
  10. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/aiohttp.py +101 -0
  11. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/bottle.py +136 -0
  12. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/cherrypy.py +108 -0
  13. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/common.py +144 -0
  14. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/django.py +438 -0
  15. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/django_static_bodies.py +1163 -0
  16. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/django_static_urls.py +1341 -0
  17. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/django_static_views.py +1073 -0
  18. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/falcon.py +121 -0
  19. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/fastapi.py +217 -0
  20. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/fastapi_static.py +1292 -0
  21. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/flask.py +1373 -0
  22. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/multipart.py +229 -0
  23. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/pyramid.py +120 -0
  24. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/response_shapes.py +273 -0
  25. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/sanic.py +63 -0
  26. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/sanic_static.py +657 -0
  27. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/starlette.py +50 -0
  28. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/starlette_static.py +1286 -0
  29. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/static_common.py +475 -0
  30. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scan/tornado.py +133 -0
  31. botversion_sdk-2.3.1/botversion_sdk/scanner_sdk/scanner.py +116 -0
  32. botversion_sdk-2.3.1/botversion_sdk/undo/__init__.py +105 -0
  33. botversion_sdk-2.3.1/botversion_sdk/undo/__main__.py +4 -0
  34. botversion_sdk-2.3.1/botversion_sdk/undo/bin/__init__.py +1 -0
  35. botversion_sdk-2.3.1/botversion_sdk/undo/bin/scan.py +16 -0
  36. botversion_sdk-2.3.1/botversion_sdk/undo/lib/__init__.py +1 -0
  37. botversion_sdk-2.3.1/botversion_sdk/undo/lib/action_id.py +37 -0
  38. botversion_sdk-2.3.1/botversion_sdk/undo/lib/capture_guard.py +18 -0
  39. botversion_sdk-2.3.1/botversion_sdk/undo/lib/capture_mongo.py +205 -0
  40. botversion_sdk-2.3.1/botversion_sdk/undo/lib/capture_mssql.py +504 -0
  41. botversion_sdk-2.3.1/botversion_sdk/undo/lib/capture_mysql.py +485 -0
  42. botversion_sdk-2.3.1/botversion_sdk/undo/lib/capture_prisma.py +311 -0
  43. botversion_sdk-2.3.1/botversion_sdk/undo/lib/capture_sql.py +546 -0
  44. botversion_sdk-2.3.1/botversion_sdk/undo/lib/capture_sqlite.py +527 -0
  45. botversion_sdk-2.3.1/botversion_sdk/undo/lib/gate.py +65 -0
  46. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/asyncpg.py +177 -0
  47. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/mongodb.py +62 -0
  48. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/mssql.py +139 -0
  49. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/mysql.py +112 -0
  50. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/prisma.py +75 -0
  51. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/psycopg.py +97 -0
  52. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/psycopg2.py +141 -0
  53. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/psycopg_async.py +96 -0
  54. botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks/sqlite.py +96 -0
  55. botversion_sdk-2.3.1/botversion_sdk/undo/lib/loader_watch.py +67 -0
  56. botversion_sdk-2.3.1/botversion_sdk/undo/lib/log.py +14 -0
  57. botversion_sdk-2.3.1/botversion_sdk/undo/lib/mssql_sql.py +156 -0
  58. botversion_sdk-2.3.1/botversion_sdk/undo/lib/mysql_sql.py +96 -0
  59. botversion_sdk-2.3.1/botversion_sdk/undo/lib/prisma_io.py +177 -0
  60. botversion_sdk-2.3.1/botversion_sdk/undo/lib/prisma_schema.py +152 -0
  61. botversion_sdk-2.3.1/botversion_sdk/undo/lib/refuse.py +6 -0
  62. botversion_sdk-2.3.1/botversion_sdk/undo/lib/report.py +35 -0
  63. botversion_sdk-2.3.1/botversion_sdk/undo/lib/requester.py +33 -0
  64. botversion_sdk-2.3.1/botversion_sdk/undo/lib/scanner.py +107 -0
  65. botversion_sdk-2.3.1/botversion_sdk/undo/lib/setup_check.py +132 -0
  66. botversion_sdk-2.3.1/botversion_sdk/undo/lib/snapshot_crypto.py +112 -0
  67. botversion_sdk-2.3.1/botversion_sdk/undo/lib/snapshot_sql.py +23 -0
  68. botversion_sdk-2.3.1/botversion_sdk/undo/lib/snapshot_store.py +141 -0
  69. botversion_sdk-2.3.1/botversion_sdk/undo/lib/snapshot_store_mongo.py +95 -0
  70. botversion_sdk-2.3.1/botversion_sdk/undo/lib/sql_classify.py +175 -0
  71. botversion_sdk-2.3.1/botversion_sdk/undo/lib/sqlite_sql.py +262 -0
  72. botversion_sdk-2.3.1/botversion_sdk/undo/lib/steps.py +22 -0
  73. botversion_sdk-2.3.1/botversion_sdk/undo/lib/tagger.py +422 -0
  74. botversion_sdk-2.3.1/botversion_sdk/undo/lib/undo_mongo.py +134 -0
  75. botversion_sdk-2.3.1/botversion_sdk/undo/lib/undo_mssql.py +248 -0
  76. botversion_sdk-2.3.1/botversion_sdk/undo/lib/undo_mysql.py +216 -0
  77. botversion_sdk-2.3.1/botversion_sdk/undo/lib/undo_pg.py +244 -0
  78. botversion_sdk-2.3.1/botversion_sdk/undo/lib/undo_prisma.py +244 -0
  79. botversion_sdk-2.3.1/botversion_sdk/undo/lib/undo_route.py +132 -0
  80. botversion_sdk-2.3.1/botversion_sdk/undo/lib/undo_sqlite.py +227 -0
  81. botversion_sdk-2.3.1/botversion_sdk/undo/register.py +5 -0
  82. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/botversion_sdk.egg-info/PKG-INFO +34 -2
  83. botversion_sdk-2.3.1/botversion_sdk.egg-info/SOURCES.txt +89 -0
  84. botversion_sdk-2.3.1/botversion_sdk.egg-info/entry_points.txt +3 -0
  85. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/botversion_sdk.egg-info/requires.txt +8 -0
  86. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/setup.py +9 -3
  87. botversion_sdk-2.2.3/botversion_sdk/bin/scan_endpoints.py +0 -59
  88. botversion_sdk-2.2.3/botversion_sdk/scanner.py +0 -2571
  89. botversion_sdk-2.2.3/botversion_sdk.egg-info/SOURCES.txt +0 -14
  90. botversion_sdk-2.2.3/botversion_sdk.egg-info/entry_points.txt +0 -2
  91. {botversion_sdk-2.2.3/botversion_sdk/bin → botversion_sdk-2.3.1/botversion_sdk/undo/lib/hooks}/__init__.py +0 -0
  92. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/botversion_sdk.egg-info/dependency_links.txt +0 -0
  93. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/botversion_sdk.egg-info/top_level.txt +0 -0
  94. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/pyproject.toml +0 -0
  95. {botversion_sdk-2.2.3 → botversion_sdk-2.3.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: botversion-sdk
3
- Version: 2.2.3
3
+ Version: 2.3.1
4
4
  Summary: BotVersion SDK — automatically discover and register your API endpoints
5
5
  Home-page: https://github.com/botversion/botversion-sdk-python
6
6
  Author: BotVersion
@@ -11,9 +11,12 @@ Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Operating System :: OS Independent
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Topic :: Software Development :: Libraries
14
- Requires-Python: >=3.7
14
+ Requires-Python: >=3.9
15
15
  Description-Content-Type: text/markdown
16
16
  Requires-Dist: python-dotenv>=1.0.0
17
+ Requires-Dist: cryptography
18
+ Requires-Dist: pglast
19
+ Requires-Dist: sqlglot
17
20
  Provides-Extra: fastapi
18
21
  Requires-Dist: fastapi; extra == "fastapi"
19
22
  Requires-Dist: starlette; extra == "fastapi"
@@ -21,9 +24,14 @@ Provides-Extra: flask
21
24
  Requires-Dist: flask; extra == "flask"
22
25
  Provides-Extra: django
23
26
  Requires-Dist: django; extra == "django"
27
+ Provides-Extra: undo
28
+ Requires-Dist: cryptography; extra == "undo"
29
+ Requires-Dist: pglast; extra == "undo"
30
+ Requires-Dist: sqlglot; extra == "undo"
24
31
  Dynamic: author
25
32
  Dynamic: author-email
26
33
  Dynamic: classifier
34
+ Dynamic: description
27
35
  Dynamic: description-content-type
28
36
  Dynamic: home-page
29
37
  Dynamic: keywords
@@ -31,3 +39,27 @@ Dynamic: provides-extra
31
39
  Dynamic: requires-dist
32
40
  Dynamic: requires-python
33
41
  Dynamic: summary
42
+
43
+ \# BotVersion SDK (Python)
44
+
45
+ BotVersion adds a self-updating AI agent to your SaaS backend.
46
+
47
+ \## What it does
48
+
49
+ \- Scans your codebase and automatically discovers your API endpoints.
50
+
51
+ \- Keeps the endpoint list live, so new endpoints are detected automatically the first time they are called.
52
+
53
+ \- Lets an AI agent act on your app through its real, current API surface, with no manual endpoint maintenance.
54
+
55
+ \## Installation
56
+
57
+   pip install botversion-sdk
58
+
59
+ \## Quick start
60
+
61
+ Add the setup snippet to your backend entry file. See the documentation on your BotVersion dashboard for the exact snippet for your framework.
62
+
63
+ \## Support
64
+
65
+ For help, contact the BotVersion team through your dashboard.
@@ -0,0 +1,23 @@
1
+ \# BotVersion SDK (Python)
2
+
3
+ BotVersion adds a self-updating AI agent to your SaaS backend.
4
+
5
+ \## What it does
6
+
7
+ \- Scans your codebase and automatically discovers your API endpoints.
8
+
9
+ \- Keeps the endpoint list live, so new endpoints are detected automatically the first time they are called.
10
+
11
+ \- Lets an AI agent act on your app through its real, current API surface, with no manual endpoint maintenance.
12
+
13
+ \## Installation
14
+
15
+   pip install botversion-sdk
16
+
17
+ \## Quick start
18
+
19
+ Add the setup snippet to your backend entry file. See the documentation on your BotVersion dashboard for the exact snippet for your framework.
20
+
21
+ \## Support
22
+
23
+ For help, contact the BotVersion team through your dashboard.
@@ -0,0 +1,19 @@
1
+ # botversion_sdk/__init__.py
2
+ # Root entry point: the host app imports botversion_sdk and calls init().
3
+ # It starts the main SDK, and also the Undo SDK when undo=True is passed.
4
+ from .scanner_sdk import init as _scanner_init, get_endpoints, register_endpoint
5
+
6
+
7
+ def init(app=None, api_key=None, **options):
8
+ # undo is ON unless the host passes undo=False
9
+ undo_enabled = options.pop("undo", True) # Undo is on unless the host passes undo=False
10
+
11
+ # Undo goes first so its request tagger is in place before the main SDK attaches
12
+ if undo_enabled:
13
+ try:
14
+ from . import undo as _undo
15
+ _undo.init(api_key=api_key, quiet=not options.get("debug", False))
16
+ except Exception as e:
17
+ pass # Undo must never break the host app or the main SDK
18
+
19
+ _scanner_init(app, api_key=api_key, **options)
@@ -1,4 +1,4 @@
1
- # botversion-sdk-python/botversion-sdk/__init__.py
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/__init__.py
2
2
  import sys
3
3
  import threading
4
4
  import builtins
@@ -152,8 +152,6 @@ def init(app=None, api_key=None, **options):
152
152
 
153
153
  if not framework:
154
154
  _initialized = False
155
- if debug:
156
- print("[botversion] No supported framework detected. SDK not initialized.")
157
155
  return
158
156
 
159
157
  _client = BotVersionClient({
@@ -0,0 +1 @@
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/bin/__init__.py
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ Build-time backend endpoint scanner. Run this as part of your deploy
4
+ pipeline (Procfile 'release' step, build.sh, or Dockerfile RUN step) so
5
+ endpoints are reported even on serverless platforms where the live
6
+ interceptor's scan-trigger route may not be reachable.
7
+ """
8
+ import json
9
+ import os
10
+ import sys
11
+
12
+ from botversion_sdk.scanner_sdk.client import BotVersionClient
13
+ from botversion_sdk.scanner_sdk.scanner import scan_routes_static, detect_framework_from_deps
14
+
15
+ # Debug output is only printed when BOTVERSION_DEBUG=1 (keeps customer builds quiet)
16
+ DEBUG = os.environ.get("BOTVERSION_DEBUG") == "1"
17
+
18
+
19
+ def dlog(*args):
20
+ if DEBUG:
21
+ print(*args)
22
+
23
+
24
+ def field_list(schema):
25
+ # Turns a schema into a short "name:type, name:type" line for easy reading
26
+ if not schema or not isinstance(schema, dict) or not schema.get("properties"):
27
+ return "-"
28
+ parts = []
29
+ for name, prop in schema["properties"].items():
30
+ if isinstance(prop, dict) and prop.get("format") == "binary":
31
+ kind = "file"
32
+ elif isinstance(prop, dict):
33
+ kind = prop.get("type", "?")
34
+ else:
35
+ kind = "?"
36
+ parts.append(f"{name}:{kind}")
37
+ line = ", ".join(parts)
38
+ if schema.get("x-content-type"):
39
+ line += f" [{schema['x-content-type']}]"
40
+ return line
41
+
42
+
43
+ def _load_env_files(cwd):
44
+ try:
45
+ from dotenv import load_dotenv
46
+ except ImportError:
47
+ return
48
+ for filename in (".env", ".env.local"):
49
+ filepath = os.path.join(cwd, filename)
50
+ if os.path.exists(filepath):
51
+ load_dotenv(filepath, override=False)
52
+
53
+
54
+ def main():
55
+ cwd = os.getcwd()
56
+ _load_env_files(cwd)
57
+
58
+ api_key = os.environ.get("BOTVERSION_API_KEY")
59
+ platform_url = os.environ.get("BOTVERSION_PLATFORM_URL", "https://console.botversion.com")
60
+ for _envname in (".env", ".env.local"):
61
+ _ep = os.path.join(cwd, _envname)
62
+ print(f"[TEMP-DEBUG] {_envname} exists:", os.path.exists(_ep))
63
+ if os.path.exists(_ep):
64
+ with open(_ep, "rb") as _ef:
65
+ _eraw = _ef.read()
66
+ print(f"[TEMP-DEBUG] {_envname} first bytes:", _eraw[:4])
67
+ _etext = _eraw.decode("utf-16", errors="ignore") if _eraw.startswith((b"\xff\xfe", b"\xfe\xff")) else _eraw.decode("utf-8", errors="ignore")
68
+ for _line in _etext.splitlines():
69
+ if "BOTVERSION" in _line.upper():
70
+ _k, _, _v = _line.partition("=")
71
+ print(f"[TEMP-DEBUG] {_envname} line:", _k, "= (masked)", repr(_v[:6] + "..." + _v[-4:]), "| value length:", len(_v))
72
+
73
+ if not api_key:
74
+ sys.exit(0)
75
+
76
+ framework = detect_framework_from_deps(cwd)
77
+ if not framework:
78
+ sys.exit(0)
79
+
80
+ endpoints = scan_routes_static(cwd, framework)
81
+
82
+ dlog("[botversion:debug] endpoints found:", len(endpoints))
83
+ for i, e in enumerate(endpoints, 1):
84
+ dlog(
85
+ f"[botversion:debug] #{i} {e.get('method')} {e.get('path')}"
86
+ f"\n request : {field_list(e.get('requestBody'))}"
87
+ f"\n response : {field_list(e.get('responseBody'))}"
88
+ f"\n params : {json.dumps(e.get('routeParamMap') or {})}"
89
+ f"\n detectedBy: {e.get('detectedBy')}"
90
+ )
91
+ dlog("[botversion:debug] full endpoint JSON:\n" + json.dumps(endpoints, indent=2, default=str))
92
+
93
+ if not endpoints:
94
+ print(f"[botversion] No backend endpoints found via static scan. detected_framework={framework}")
95
+ sys.exit(0)
96
+
97
+ client = BotVersionClient({"api_key": api_key, "platform_url": platform_url, "debug": True})
98
+ # TEMP-DEBUG: send one endpoint directly so the real error shows
99
+ try:
100
+ _resp = client._post("/api/sdk/register-endpoints", {"workspaceKey": api_key, "endpoints": endpoints[:1]})
101
+ print("[TEMP-DEBUG] test post response:", _resp)
102
+ except Exception as _e:
103
+ print("[TEMP-DEBUG] test post failed:", repr(_e))
104
+ try:
105
+ client.register_endpoints_now(endpoints)
106
+ print(f"[botversion] Reported {len(endpoints)} backend endpoints. detected_framework={framework}")
107
+ except Exception as e:
108
+ print(f"[botversion] Failed to report backend endpoints: {e}")
109
+
110
+ sys.exit(0)
111
+
112
+
113
+ if __name__ == "__main__":
114
+ main()
@@ -1,4 +1,4 @@
1
- # botversion-sdk-python/botversion-sdk/client.py
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/client.py
2
2
  import json
3
3
  import threading
4
4
  import urllib.request
@@ -1,4 +1,4 @@
1
- # botversion-sdk-python/botversion-sdk/interceptor.py
1
+ # botversion-sdk-python/botversion-sdk/scanner-sdk/interceptor.py
2
2
  import re
3
3
  import json
4
4
  import threading
@@ -519,7 +519,7 @@ def attach_django_interceptor(client, options):
519
519
  try:
520
520
  from django.conf import settings
521
521
 
522
- middleware_path = "botversion_sdk.interceptor.BotVersionDjangoMiddleware"
522
+ middleware_path = __name__ + ".BotVersionDjangoMiddleware" # built from this file's real module path so it survives file moves
523
523
 
524
524
  if middleware_path not in settings.MIDDLEWARE:
525
525
  if isinstance(settings.MIDDLEWARE, tuple):
@@ -1071,7 +1071,7 @@ def attach_pyramid_interceptor(app, client, options):
1071
1071
  For Pyramid, the tween must be added during config before app creation.
1072
1072
  We store client + options at module level so the tween factory can use them.
1073
1073
  Tell the user to add this to their Pyramid config:
1074
- config.add_tween('botversion_sdk.interceptor.botversion_pyramid_tween_factory')
1074
+ config.add_tween(__name__ + ".botversion_pyramid_tween_factory") # built from this file's real module path so it survives file moves
1075
1075
  """
1076
1076
  global _pyramid_client, _pyramid_options
1077
1077
  _pyramid_client = client
@@ -0,0 +1,2 @@
1
+ # botversion-sdk-python/botversion_sdk/scan/__init__.py
2
+
@@ -0,0 +1,101 @@
1
+ # botversion-sdk-python/botversion_sdk/scan/aiohttp.py
2
+
3
+ import re
4
+
5
+ from .common import generate_description
6
+ from .multipart import live_multipart
7
+ from .response_shapes import _resolve_view_handler, extract_static_response_from_callable
8
+ from .static_common import _extract_body_fields_static, _walk_py_files
9
+
10
+
11
+ # ── aiohttp ───────────────────────────────────────────────────────────────────
12
+ # aiohttp stores routes in app.router which has a resources() method
13
+
14
+ def scan_aiohttp_routes(app):
15
+ endpoints = []
16
+ seen = set()
17
+
18
+ try:
19
+ for resource in app.router.resources():
20
+ path = resource.canonical
21
+ # Normalize {param} → :param
22
+ normalized_path = re.sub(r"\{([^:}]+)(?::[^}]+)?\}", r":\1", path)
23
+ normalized_path = normalized_path.rstrip("/") or "/"
24
+
25
+ # Each resource has routes with methods
26
+ for route in resource:
27
+ method = route.method.upper()
28
+ if method in ("HEAD", "OPTIONS", "*"):
29
+ continue
30
+
31
+ key = f"{method}:{normalized_path}"
32
+ if key in seen:
33
+ continue
34
+ seen.add(key)
35
+
36
+ handler = route.handler
37
+ handler_name = getattr(handler, "__name__", None)
38
+
39
+ endpoints.append({
40
+ "method": method,
41
+ "path": normalized_path,
42
+ "description": generate_description(method, normalized_path, handler_name),
43
+ "requestBody": live_multipart(_resolve_view_handler(handler, method), method),
44
+ "responseBody": extract_static_response_from_callable(_resolve_view_handler(handler, method)),
45
+ "detectedBy": "static-scan",
46
+ })
47
+
48
+ except Exception:
49
+ pass
50
+
51
+ return endpoints
52
+
53
+
54
+ def _scan_aiohttp_static(cwd):
55
+ """
56
+ Handles aiohttp-style route registration:
57
+ app.router.add_get('/path', handler)
58
+ app.router.add_post('/path', handler)
59
+ app.router.add_route('POST', '/path', handler)
60
+ """
61
+ endpoints = []
62
+ seen = set()
63
+
64
+ shorthand_pattern = re.compile(
65
+ r"add_(get|post|put|delete|patch)\s*\(\s*[\"']([^\"']+)[\"']",
66
+ re.IGNORECASE,
67
+ )
68
+ generic_pattern = re.compile(
69
+ r"add_route\s*\(\s*[\"'](\w+)[\"']\s*,\s*[\"']([^\"']+)[\"']",
70
+ re.IGNORECASE,
71
+ )
72
+
73
+ for filepath in _walk_py_files(cwd):
74
+ try:
75
+ with open(filepath, "r", encoding="utf-8", errors="ignore") as fh:
76
+ content = fh.read()
77
+ except Exception:
78
+ continue
79
+
80
+ for pattern in (shorthand_pattern, generic_pattern):
81
+ for match in pattern.finditer(content):
82
+ method = match.group(1).upper()
83
+ path = match.group(2)
84
+ normalized = re.sub(r"\{([^:}]+)(?::[^}]+)?\}", r":\1", path)
85
+
86
+ key = f"{method}:{normalized}"
87
+ if key in seen:
88
+ continue
89
+ seen.add(key)
90
+
91
+ body_fields = _extract_body_fields_static(content) if method in ("POST", "PUT", "PATCH") else None
92
+
93
+ endpoints.append({
94
+ "method": method,
95
+ "path": normalized,
96
+ "description": generate_description(method, normalized, None),
97
+ "requestBody": body_fields,
98
+ "detectedBy": "static-scan-file",
99
+ })
100
+
101
+ return endpoints
@@ -0,0 +1,136 @@
1
+ # botversion-sdk-python/botversion_sdk/scan/bottle.py
2
+
3
+ import re
4
+
5
+ from .common import generate_description
6
+ from .multipart import extract_multipart_static_at, live_multipart, merge_body_with_multipart
7
+ from .response_shapes import (
8
+ extract_static_response_at,
9
+ extract_static_response_from_callable,
10
+ parse_source_tree,
11
+ )
12
+ from .static_common import _extract_body_fields_static, _find_matching_paren, _walk_py_files
13
+
14
+
15
+ # ── Bottle ────────────────────────────────────────────────────────────────────
16
+ # Bottle stores all routes in app.routes (a list of Route objects)
17
+
18
+ def scan_bottle_routes(app):
19
+ endpoints = []
20
+ seen = set()
21
+
22
+ try:
23
+ for route in app.routes:
24
+ path = route.rule
25
+ method = route.method.upper()
26
+
27
+ if method in ("HEAD", "OPTIONS"):
28
+ continue
29
+ if path in ("/static", "/_"):
30
+ continue
31
+
32
+ # Normalize <param> or <param:type> → :param
33
+ normalized_path = re.sub(r"<([^:>]+)(?::[^>]+)?>", r":\1", path)
34
+ normalized_path = normalized_path.rstrip("/") or "/"
35
+
36
+ key = f"{method}:{normalized_path}"
37
+ if key in seen:
38
+ continue
39
+ seen.add(key)
40
+
41
+ handler_name = getattr(route.callback, "__name__", None)
42
+
43
+ endpoints.append({
44
+ "method": method,
45
+ "path": normalized_path,
46
+ "description": generate_description(method, normalized_path, handler_name),
47
+ "requestBody": live_multipart(route.callback, method),
48
+ "responseBody": extract_static_response_from_callable(route.callback),
49
+ "detectedBy": "static-scan",
50
+ })
51
+
52
+ except Exception:
53
+ pass
54
+
55
+ return endpoints
56
+
57
+
58
+ def _scan_bottle_static(cwd):
59
+ """
60
+ Handles Bottle-style routes:
61
+ @app.route('/path', method='POST')
62
+ @app.get('/path') / @app.post('/path') (shorthand decorators)
63
+ """
64
+ endpoints = []
65
+ seen = set()
66
+
67
+ shorthand_pattern = re.compile(
68
+ r"@(?:\w+)\.(get|post|put|delete|patch)\s*\(\s*[\"']([^\"']+)[\"']",
69
+ re.IGNORECASE,
70
+ )
71
+ route_decorator_start = re.compile(r"@(?:\w+)\.route\s*\(", re.IGNORECASE)
72
+
73
+ for filepath in _walk_py_files(cwd):
74
+ try:
75
+ with open(filepath, "r", encoding="utf-8", errors="ignore") as fh:
76
+ content = fh.read()
77
+ except Exception:
78
+ continue
79
+
80
+ tree = parse_source_tree(content)
81
+
82
+ for match in shorthand_pattern.finditer(content):
83
+ method = match.group(1).upper()
84
+ path = match.group(2)
85
+ normalized = re.sub(r"<([^:>]+)(?::[^>]+)?>", r":\1", path)
86
+
87
+ key = f"{method}:{normalized}"
88
+ if key in seen:
89
+ continue
90
+ seen.add(key)
91
+
92
+ body_fields = _extract_body_fields_static(content) if method in ("POST", "PUT", "PATCH") else None
93
+
94
+ endpoints.append({
95
+ "method": method,
96
+ "path": normalized,
97
+ "description": generate_description(method, normalized, None),
98
+ "requestBody": merge_body_with_multipart(body_fields, extract_multipart_static_at(tree, content, match.start(), method)),
99
+ "responseBody": extract_static_response_at(tree, content, match.start()),
100
+ "detectedBy": "static-scan-file",
101
+ })
102
+
103
+ for start_match in route_decorator_start.finditer(content):
104
+ open_idx = start_match.end() - 1
105
+ close_idx = _find_matching_paren(content, open_idx)
106
+ if close_idx is None:
107
+ continue
108
+ args_text = content[open_idx + 1:close_idx]
109
+
110
+ path_match = re.search(r"[\"']([^\"']+)[\"']", args_text)
111
+ if not path_match:
112
+ continue
113
+ path = path_match.group(1)
114
+
115
+ method_match = re.search(r"method\s*=\s*[\"'](\w+)[\"']", args_text)
116
+ method = method_match.group(1).upper() if method_match else "GET"
117
+
118
+ normalized = re.sub(r"<([^:>]+)(?::[^>]+)?>", r":\1", path)
119
+
120
+ key = f"{method}:{normalized}"
121
+ if key in seen:
122
+ continue
123
+ seen.add(key)
124
+
125
+ body_fields = _extract_body_fields_static(content) if method in ("POST", "PUT", "PATCH") else None
126
+
127
+ endpoints.append({
128
+ "method": method,
129
+ "path": normalized,
130
+ "description": generate_description(method, normalized, None),
131
+ "requestBody": merge_body_with_multipart(body_fields, extract_multipart_static_at(tree, content, start_match.start(), method)),
132
+ "responseBody": extract_static_response_at(tree, content, start_match.start()),
133
+ "detectedBy": "static-scan-file",
134
+ })
135
+
136
+ return endpoints
@@ -0,0 +1,108 @@
1
+ # botversion-sdk-python/botversion_sdk/scan/cherrypy.py
2
+
3
+ import inspect
4
+
5
+ from .common import generate_description
6
+ from .multipart import cherrypy_multipart
7
+ from .response_shapes import extract_static_response_from_callable
8
+
9
+
10
+ # ── CherryPy ──────────────────────────────────────────────────────────────────
11
+ # CherryPy uses a tree-based dispatcher. Routes are methods on classes.
12
+ # We walk the mounted apps and find exposed methods.
13
+
14
+ def scan_cherrypy_routes(app):
15
+ endpoints = []
16
+ seen = set()
17
+
18
+ HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"]
19
+
20
+ try:
21
+ import cherrypy
22
+
23
+ def walk_cherrypy_tree(obj, prefix=""):
24
+ # Check if this object has exposed methods (HTTP handlers)
25
+ for method_name in [m.lower() for m in HTTP_METHODS]:
26
+ # MethodDispatcher resources name handlers in capitals (GET, POST) and expose the whole class
27
+ fn = getattr(obj, method_name, None) or getattr(obj, method_name.upper(), None)
28
+ if fn and (getattr(fn, "exposed", False) or getattr(obj, "exposed", False)):
29
+ method = method_name.upper()
30
+ path = prefix or "/"
31
+ key = f"{method}:{path}"
32
+ if key not in seen:
33
+ seen.add(key)
34
+ endpoints.append({
35
+ "method": method,
36
+ "path": path,
37
+ "description": generate_description(method, path, fn.__name__),
38
+ "requestBody": cherrypy_multipart(fn, method),
39
+ "responseBody": extract_static_response_from_callable(fn),
40
+ "detectedBy": "static-scan",
41
+ })
42
+
43
+ # index() is the default handler for the path (like GET /)
44
+ index_fn = getattr(obj, "index", None)
45
+ if index_fn and getattr(index_fn, "exposed", False):
46
+ path = prefix or "/"
47
+ key = f"GET:{path}"
48
+ if key not in seen:
49
+ seen.add(key)
50
+ endpoints.append({
51
+ "method": "GET",
52
+ "path": path,
53
+ "description": generate_description("GET", path, "index"),
54
+ "requestBody": None,
55
+ "responseBody": extract_static_response_from_callable(index_fn),
56
+ "detectedBy": "static-scan",
57
+ })
58
+
59
+ # Walk child attributes (sub-paths)
60
+ visited = set()
61
+
62
+ for attr_name in dir(obj):
63
+ if attr_name.startswith("_"):
64
+ continue
65
+ child = getattr(obj, attr_name, None)
66
+ if child is None:
67
+ continue
68
+ # Ordinary exposed methods (e.g. def upload(self, ...)) are reachable by name with any HTTP method
69
+ if (
70
+ (inspect.ismethod(child) or inspect.isfunction(child))
71
+ and getattr(child, "exposed", False)
72
+ and attr_name.lower() not in ("index", "default", "favicon_ico") + tuple(m.lower() for m in HTTP_METHODS)
73
+ ):
74
+ child_path = prefix + "/" + attr_name
75
+ upload = cherrypy_multipart(child, "POST")
76
+ for named_method in (["POST"] if upload else ["GET", "POST"]):
77
+ key = f"{named_method}:{child_path}"
78
+ if key in seen:
79
+ continue
80
+ seen.add(key)
81
+ endpoints.append({
82
+ "method": named_method,
83
+ "path": child_path,
84
+ "description": generate_description(named_method, child_path, attr_name),
85
+ "requestBody": upload if named_method == "POST" else None,
86
+ "responseBody": extract_static_response_from_callable(child),
87
+ "detectedBy": "static-scan",
88
+ })
89
+ continue
90
+ child_id = id(child)
91
+ if child_id in visited:
92
+ continue
93
+ visited.add(child_id)
94
+ if hasattr(child, "exposed") or any(
95
+ hasattr(child, m.lower()) for m in HTTP_METHODS
96
+ ):
97
+ walk_cherrypy_tree(child, prefix + "/" + attr_name)
98
+
99
+ # Walk all mounted apps in cherrypy.tree
100
+ for script_name, app_entry in cherrypy.tree.apps.items():
101
+ root = getattr(app_entry, "root", None)
102
+ if root:
103
+ walk_cherrypy_tree(root, script_name)
104
+
105
+ except Exception:
106
+ pass
107
+
108
+ return endpoints