debug-assist 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,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: debug-assist
3
+ Version: 1.0.0
4
+ Summary: Auto-capture runtime errors and send diagnostics to DebugAssist API
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/debug-assist/sdk-python
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+
13
+ # DebugAssist Python SDK
14
+
15
+ Auto-capture runtime errors and send diagnostics to [DebugAssist](https://debug-assist.app).
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pip install debug-assist
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ # Auto mode — set env var and import
27
+ import os
28
+ os.environ['DEBUG_ASSIST_API_KEY'] = 'your-api-key'
29
+ import debug_assist # unhandled exceptions are captured automatically
30
+
31
+ # Explicit mode
32
+ from debug_assist import DebugAssist
33
+ DebugAssist.init(api_key='your-api-key', project_name='my-app')
34
+
35
+ # Manual report
36
+ client = DebugAssist(api_key='your-api-key')
37
+ client.report(tipo='silent_backend_error', mensagem='something went wrong')
38
+ ```
39
+
40
+ ## Environment Variables
41
+
42
+ | Variable | Description | Default |
43
+ |----------|-------------|---------|
44
+ | `DEBUG_ASSIST_API_KEY` | Your API key | — |
45
+ | `DEBUG_ASSIST_PROJECT` | Project name shown in diagnostics | `unknown` |
46
+ | `DEBUG_ASSIST_BASE_URL` | API base URL | `https://debug-assist.onrender.com` |
47
+ | `DEBUG_ASSIST_ENABLED` | Set to `0` to disable | `1` |
@@ -0,0 +1,35 @@
1
+ # DebugAssist Python SDK
2
+
3
+ Auto-capture runtime errors and send diagnostics to [DebugAssist](https://debug-assist.app).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install debug-assist
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ # Auto mode — set env var and import
15
+ import os
16
+ os.environ['DEBUG_ASSIST_API_KEY'] = 'your-api-key'
17
+ import debug_assist # unhandled exceptions are captured automatically
18
+
19
+ # Explicit mode
20
+ from debug_assist import DebugAssist
21
+ DebugAssist.init(api_key='your-api-key', project_name='my-app')
22
+
23
+ # Manual report
24
+ client = DebugAssist(api_key='your-api-key')
25
+ client.report(tipo='silent_backend_error', mensagem='something went wrong')
26
+ ```
27
+
28
+ ## Environment Variables
29
+
30
+ | Variable | Description | Default |
31
+ |----------|-------------|---------|
32
+ | `DEBUG_ASSIST_API_KEY` | Your API key | — |
33
+ | `DEBUG_ASSIST_PROJECT` | Project name shown in diagnostics | `unknown` |
34
+ | `DEBUG_ASSIST_BASE_URL` | API base URL | `https://debug-assist.onrender.com` |
35
+ | `DEBUG_ASSIST_ENABLED` | Set to `0` to disable | `1` |
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: debug-assist
3
+ Version: 1.0.0
4
+ Summary: Auto-capture runtime errors and send diagnostics to DebugAssist API
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/debug-assist/sdk-python
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+
13
+ # DebugAssist Python SDK
14
+
15
+ Auto-capture runtime errors and send diagnostics to [DebugAssist](https://debug-assist.app).
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ pip install debug-assist
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ # Auto mode — set env var and import
27
+ import os
28
+ os.environ['DEBUG_ASSIST_API_KEY'] = 'your-api-key'
29
+ import debug_assist # unhandled exceptions are captured automatically
30
+
31
+ # Explicit mode
32
+ from debug_assist import DebugAssist
33
+ DebugAssist.init(api_key='your-api-key', project_name='my-app')
34
+
35
+ # Manual report
36
+ client = DebugAssist(api_key='your-api-key')
37
+ client.report(tipo='silent_backend_error', mensagem='something went wrong')
38
+ ```
39
+
40
+ ## Environment Variables
41
+
42
+ | Variable | Description | Default |
43
+ |----------|-------------|---------|
44
+ | `DEBUG_ASSIST_API_KEY` | Your API key | — |
45
+ | `DEBUG_ASSIST_PROJECT` | Project name shown in diagnostics | `unknown` |
46
+ | `DEBUG_ASSIST_BASE_URL` | API base URL | `https://debug-assist.onrender.com` |
47
+ | `DEBUG_ASSIST_ENABLED` | Set to `0` to disable | `1` |
@@ -0,0 +1,7 @@
1
+ README.md
2
+ debug_assist.py
3
+ pyproject.toml
4
+ debug_assist.egg-info/PKG-INFO
5
+ debug_assist.egg-info/SOURCES.txt
6
+ debug_assist.egg-info/dependency_links.txt
7
+ debug_assist.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ debug_assist
@@ -0,0 +1,116 @@
1
+ """
2
+ DebugAssist Python SDK
3
+
4
+ Captura automaticamente exceções não tratadas e envia para a API DebugAssist.
5
+
6
+ Modo mais simples — via variável de ambiente:
7
+ export DEBUG_ASSIST_API_KEY='SUA_API_KEY'
8
+ import debug_assist # só isso já basta, monitoramento ativado
9
+
10
+ Modo explícito (quando a chave vem do código):
11
+ from debug_assist import DebugAssist
12
+ DebugAssist.init(api_key='SUA_API_KEY', project_name='meu-projeto')
13
+
14
+ Envio manual:
15
+ client = DebugAssist(api_key='SUA_API_KEY')
16
+ client.report(tipo='silent_backend_error', mensagem=str(e))
17
+ """
18
+
19
+ import json
20
+ import os
21
+ import sys
22
+ import traceback
23
+ import urllib.request
24
+
25
+ DEFAULT_BASE_URL = 'https://debug-assist.onrender.com'
26
+
27
+
28
+ class DebugAssist:
29
+ _initialized = False
30
+
31
+ def __init__(self, api_key, base_url=None):
32
+ if not api_key:
33
+ raise ValueError('DebugAssist: api_key é obrigatória')
34
+ self.api_key = api_key
35
+ self.base_url = (base_url or DEFAULT_BASE_URL).rstrip('/')
36
+
37
+ def report(self, tipo, mensagem='', contexto=None, dados=None):
38
+ """Envia um diagnóstico para a API DebugAssist.
39
+
40
+ Args:
41
+ tipo: Categoria do erro (ex: 'silent_backend_error', 'sql_analysis').
42
+ mensagem: Mensagem de erro (ex: str(e)).
43
+ contexto: Dict com dados adicionais (rota, método, etc.).
44
+ dados: Dict para sql_analysis (query, tempo_execucao).
45
+
46
+ Returns:
47
+ Dict com o diagnóstico retornado pela API.
48
+ """
49
+ if not tipo:
50
+ raise ValueError("DebugAssist: campo 'tipo' é obrigatório")
51
+
52
+ body = {'tipo': tipo, 'mensagem': mensagem}
53
+ if contexto:
54
+ body['contexto'] = contexto
55
+ if dados:
56
+ body['dados'] = dados
57
+
58
+ encoded = json.dumps(body).encode('utf-8')
59
+ req = urllib.request.Request(
60
+ f'{self.base_url}/v1/diagnosticos',
61
+ data=encoded,
62
+ method='POST',
63
+ )
64
+ req.add_header('Content-Type', 'application/json')
65
+ req.add_header('Authorization', f'Bearer {self.api_key}')
66
+
67
+ with urllib.request.urlopen(req, timeout=30) as resp:
68
+ return json.loads(resp.read().decode('utf-8'))
69
+
70
+ @classmethod
71
+ def init(cls, api_key, project_name='unknown', base_url=None):
72
+ """Registra o hook de exceções não tratadas.
73
+
74
+ Após chamar init(), qualquer exceção que derrube o processo é
75
+ automaticamente enviada para a API antes de encerrar.
76
+
77
+ Args:
78
+ api_key: Sua API Key (obtida em /v1/auth/me).
79
+ project_name: Nome do projeto (aparece no contexto do diagnóstico).
80
+ base_url: URL base da API (padrão: https://debug-assist.onrender.com).
81
+ """
82
+ if cls._initialized:
83
+ return
84
+
85
+ client = cls(api_key=api_key, base_url=base_url)
86
+ cls._initialized = True
87
+
88
+ original_excepthook = sys.excepthook
89
+
90
+ def _excepthook(exc_type, exc_value, exc_traceback):
91
+ stack = ''.join(traceback.format_tb(exc_traceback))
92
+ try:
93
+ client.report(
94
+ tipo='silent_backend_error',
95
+ mensagem=str(exc_value),
96
+ contexto={
97
+ 'project_name': project_name,
98
+ 'exception_type': exc_type.__name__,
99
+ 'stack': stack,
100
+ },
101
+ )
102
+ except Exception:
103
+ pass
104
+ original_excepthook(exc_type, exc_value, exc_traceback)
105
+
106
+ sys.excepthook = _excepthook
107
+
108
+
109
+ # Auto-inicializa se DEBUG_ASSIST_API_KEY estiver no ambiente
110
+ _env_key = os.getenv('DEBUG_ASSIST_API_KEY')
111
+ if _env_key and os.getenv('DEBUG_ASSIST_ENABLED', '1') != '0':
112
+ DebugAssist.init(
113
+ api_key=_env_key,
114
+ project_name=os.getenv('DEBUG_ASSIST_PROJECT', 'unknown'),
115
+ base_url=os.getenv('DEBUG_ASSIST_BASE_URL'),
116
+ )
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "debug-assist"
7
+ version = "1.0.0"
8
+ description = "Auto-capture runtime errors and send diagnostics to DebugAssist API"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/debug-assist/sdk-python"
20
+
21
+ [tool.setuptools]
22
+ py-modules = ["debug_assist"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+