secploy 0.1.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.
- secploy-0.1.0/LICENSE +21 -0
- secploy-0.1.0/MANIFEST.in +2 -0
- secploy-0.1.0/PKG-INFO +204 -0
- secploy-0.1.0/README.md +171 -0
- secploy-0.1.0/pyproject.toml +19 -0
- secploy-0.1.0/secploy/__init__.py +5 -0
- secploy-0.1.0/secploy/client.py +60 -0
- secploy-0.1.0/secploy/config.py +5 -0
- secploy-0.1.0/secploy/events.py +33 -0
- secploy-0.1.0/secploy/exceptions.py +0 -0
- secploy-0.1.0/secploy/heartbeat.py +25 -0
- secploy-0.1.0/secploy/utils.py +5 -0
- secploy-0.1.0/secploy.egg-info/PKG-INFO +204 -0
- secploy-0.1.0/secploy.egg-info/SOURCES.txt +24 -0
- secploy-0.1.0/secploy.egg-info/dependency_links.txt +1 -0
- secploy-0.1.0/secploy.egg-info/requires.txt +1 -0
- secploy-0.1.0/secploy.egg-info/top_level.txt +1 -0
- secploy-0.1.0/setup.cfg +11 -0
secploy-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 AGASTRONICS
|
|
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.
|
secploy-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: secploy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Secploy security monitoring and event tracking
|
|
5
|
+
Author-email: Abdulsamad Abdulganiyu <agastronics@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 AGASTRONICS
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Requires-Python: >=3.7
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: requests>=2.20.0
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="https://secploy.vercel.app/logo.png" alt="Secploy Logo" width="180">
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<h1 align="center">Secploy Python SDK</h1>
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<em>Event tracking, heartbeat monitoring, and real-time status updates for your apps β powered by Secploy.</em>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## π Overview
|
|
47
|
+
|
|
48
|
+
**Secploy** is a modern **security monitoring and observability platform** that helps you track **events, uptime, and live statuses** in real time.
|
|
49
|
+
|
|
50
|
+
With the **Secploy Python SDK**, you can:
|
|
51
|
+
- β
Send **events** from your Python applications or microservices.
|
|
52
|
+
- π Monitor uptime & availability using **heartbeats**.
|
|
53
|
+
- π Attach **environment** and **project metadata** automatically.
|
|
54
|
+
- π‘ Receive **live project statuses** in your Secploy dashboard (`Running`, `Idle`, `Shutdown`).
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## π Installation
|
|
59
|
+
|
|
60
|
+
Install directly from **PyPI**:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install secploy
|
|
64
|
+
````
|
|
65
|
+
|
|
66
|
+
Or from source:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
git clone https://github.com/your-org/secploy-python-sdk.git
|
|
70
|
+
cd secploy-python-sdk
|
|
71
|
+
pip install .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## β‘ Quick Start
|
|
77
|
+
|
|
78
|
+
### 1οΈβ£ Initialize the Client
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from secploy import SecployClient
|
|
82
|
+
|
|
83
|
+
client = SecployClient(
|
|
84
|
+
api_key="your_project_api_key",
|
|
85
|
+
environment="production"
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### 2οΈβ£ Send Events
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
client.track_event(
|
|
95
|
+
name="user_signup",
|
|
96
|
+
properties={
|
|
97
|
+
"user_id": 101,
|
|
98
|
+
"plan": "pro",
|
|
99
|
+
"referral": "campaign_2025"
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### 3οΈβ£ Report an Incident
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
incident = client.create_incident(
|
|
110
|
+
title="High Error Rate",
|
|
111
|
+
description="API error rate exceeded 5% in the EU region.",
|
|
112
|
+
severity="critical"
|
|
113
|
+
)
|
|
114
|
+
print("Incident ID:", incident.id)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### 4οΈβ£ Monitor Heartbeats
|
|
120
|
+
|
|
121
|
+
*(Ideal for background jobs, services, or scheduled tasks)*
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import time
|
|
125
|
+
|
|
126
|
+
while True:
|
|
127
|
+
client.heartbeat()
|
|
128
|
+
time.sleep(60) # every minute
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### 5οΈβ£ Listen for Live Status Updates
|
|
134
|
+
|
|
135
|
+
*(Requires WebSocket + Django Channels backend)*
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
for status in client.listen_status():
|
|
139
|
+
print(f"[STATUS UPDATE] Project is now {status}")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Possible statuses:
|
|
143
|
+
|
|
144
|
+
* `running`
|
|
145
|
+
* `idle`
|
|
146
|
+
* `shutdown`
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## π Environments
|
|
151
|
+
|
|
152
|
+
When you create a project in Secploy, multiple environments are automatically created:
|
|
153
|
+
|
|
154
|
+
| Environment | Purpose |
|
|
155
|
+
| ------------- | ---------------------- |
|
|
156
|
+
| `production` | Live, customer-facing |
|
|
157
|
+
| `staging` | Pre-production testing |
|
|
158
|
+
| `development` | Local development |
|
|
159
|
+
|
|
160
|
+
Each environment has its own **API key** β use the matching key for the environment youβre sending data from.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## π‘ SDK Methods
|
|
165
|
+
|
|
166
|
+
| Method | Description |
|
|
167
|
+
| ----------------------------------------------- | ------------------------------ |
|
|
168
|
+
| `track_event(name, properties)` | Send a structured event |
|
|
169
|
+
| `create_incident(title, description, severity)` | Create a new incident |
|
|
170
|
+
| `heartbeat()` | Send a heartbeat signal |
|
|
171
|
+
| `listen_status()` | Stream live project status |
|
|
172
|
+
| `set_environment(env_code)` | Switch environment dynamically |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## π‘ Requirements
|
|
177
|
+
|
|
178
|
+
* Python **3.8+**
|
|
179
|
+
* `requests`
|
|
180
|
+
* `websocket-client`
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## π€ Contributing
|
|
185
|
+
|
|
186
|
+
1. Fork the repo
|
|
187
|
+
2. Create your feature branch:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
git checkout -b feature/my-feature
|
|
191
|
+
```
|
|
192
|
+
3. Commit your changes:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
git commit -m "Add my feature"
|
|
196
|
+
```
|
|
197
|
+
4. Push to the branch and open a Pull Request
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## π License
|
|
202
|
+
|
|
203
|
+
MIT License β See [LICENSE](LICENSE) for details.
|
|
204
|
+
|
secploy-0.1.0/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://secploy.vercel.app/logo.png" alt="Secploy Logo" width="180">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Secploy Python SDK</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<em>Event tracking, heartbeat monitoring, and real-time status updates for your apps β powered by Secploy.</em>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## π Overview
|
|
14
|
+
|
|
15
|
+
**Secploy** is a modern **security monitoring and observability platform** that helps you track **events, uptime, and live statuses** in real time.
|
|
16
|
+
|
|
17
|
+
With the **Secploy Python SDK**, you can:
|
|
18
|
+
- β
Send **events** from your Python applications or microservices.
|
|
19
|
+
- π Monitor uptime & availability using **heartbeats**.
|
|
20
|
+
- π Attach **environment** and **project metadata** automatically.
|
|
21
|
+
- π‘ Receive **live project statuses** in your Secploy dashboard (`Running`, `Idle`, `Shutdown`).
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## π Installation
|
|
26
|
+
|
|
27
|
+
Install directly from **PyPI**:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install secploy
|
|
31
|
+
````
|
|
32
|
+
|
|
33
|
+
Or from source:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/your-org/secploy-python-sdk.git
|
|
37
|
+
cd secploy-python-sdk
|
|
38
|
+
pip install .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## β‘ Quick Start
|
|
44
|
+
|
|
45
|
+
### 1οΈβ£ Initialize the Client
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from secploy import SecployClient
|
|
49
|
+
|
|
50
|
+
client = SecployClient(
|
|
51
|
+
api_key="your_project_api_key",
|
|
52
|
+
environment="production"
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### 2οΈβ£ Send Events
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
client.track_event(
|
|
62
|
+
name="user_signup",
|
|
63
|
+
properties={
|
|
64
|
+
"user_id": 101,
|
|
65
|
+
"plan": "pro",
|
|
66
|
+
"referral": "campaign_2025"
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### 3οΈβ£ Report an Incident
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
incident = client.create_incident(
|
|
77
|
+
title="High Error Rate",
|
|
78
|
+
description="API error rate exceeded 5% in the EU region.",
|
|
79
|
+
severity="critical"
|
|
80
|
+
)
|
|
81
|
+
print("Incident ID:", incident.id)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
### 4οΈβ£ Monitor Heartbeats
|
|
87
|
+
|
|
88
|
+
*(Ideal for background jobs, services, or scheduled tasks)*
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
import time
|
|
92
|
+
|
|
93
|
+
while True:
|
|
94
|
+
client.heartbeat()
|
|
95
|
+
time.sleep(60) # every minute
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### 5οΈβ£ Listen for Live Status Updates
|
|
101
|
+
|
|
102
|
+
*(Requires WebSocket + Django Channels backend)*
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
for status in client.listen_status():
|
|
106
|
+
print(f"[STATUS UPDATE] Project is now {status}")
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Possible statuses:
|
|
110
|
+
|
|
111
|
+
* `running`
|
|
112
|
+
* `idle`
|
|
113
|
+
* `shutdown`
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## π Environments
|
|
118
|
+
|
|
119
|
+
When you create a project in Secploy, multiple environments are automatically created:
|
|
120
|
+
|
|
121
|
+
| Environment | Purpose |
|
|
122
|
+
| ------------- | ---------------------- |
|
|
123
|
+
| `production` | Live, customer-facing |
|
|
124
|
+
| `staging` | Pre-production testing |
|
|
125
|
+
| `development` | Local development |
|
|
126
|
+
|
|
127
|
+
Each environment has its own **API key** β use the matching key for the environment youβre sending data from.
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## π‘ SDK Methods
|
|
132
|
+
|
|
133
|
+
| Method | Description |
|
|
134
|
+
| ----------------------------------------------- | ------------------------------ |
|
|
135
|
+
| `track_event(name, properties)` | Send a structured event |
|
|
136
|
+
| `create_incident(title, description, severity)` | Create a new incident |
|
|
137
|
+
| `heartbeat()` | Send a heartbeat signal |
|
|
138
|
+
| `listen_status()` | Stream live project status |
|
|
139
|
+
| `set_environment(env_code)` | Switch environment dynamically |
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## π‘ Requirements
|
|
144
|
+
|
|
145
|
+
* Python **3.8+**
|
|
146
|
+
* `requests`
|
|
147
|
+
* `websocket-client`
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## π€ Contributing
|
|
152
|
+
|
|
153
|
+
1. Fork the repo
|
|
154
|
+
2. Create your feature branch:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
git checkout -b feature/my-feature
|
|
158
|
+
```
|
|
159
|
+
3. Commit your changes:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
git commit -m "Add my feature"
|
|
163
|
+
```
|
|
164
|
+
4. Push to the branch and open a Pull Request
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## π License
|
|
169
|
+
|
|
170
|
+
MIT License β See [LICENSE](LICENSE) for details.
|
|
171
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "secploy"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python SDK for Secploy security monitoring and event tracking"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name="Abdulsamad Abdulganiyu", email="agastronics@gmail.com" }
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = {file="LICENSE"}
|
|
14
|
+
requires-python = ">=3.7"
|
|
15
|
+
dependencies = ["requests>=2.20.0"]
|
|
16
|
+
|
|
17
|
+
[tool.setuptools]
|
|
18
|
+
packages = ["secploy"]
|
|
19
|
+
package-dir = {"" = "."}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
import time
|
|
3
|
+
import requests
|
|
4
|
+
|
|
5
|
+
from lib.secploy_logger import setup_logger
|
|
6
|
+
from .utils import log
|
|
7
|
+
|
|
8
|
+
class SecployClient:
|
|
9
|
+
def __init__(self, api_key, ingest_url, heartbeat_interval=30, max_retry=3, debug=False, log_level='INFO'):
|
|
10
|
+
self.api_key = api_key
|
|
11
|
+
self.ingest_url = ingest_url.rstrip("/")
|
|
12
|
+
self.heartbeat_interval = heartbeat_interval
|
|
13
|
+
self.max_retry = max_retry
|
|
14
|
+
self.debug = debug
|
|
15
|
+
self.log_level = log_level
|
|
16
|
+
self._stop_event = threading.Event()
|
|
17
|
+
self._thread = None
|
|
18
|
+
setup_logger(log_level=log_level)
|
|
19
|
+
|
|
20
|
+
def _headers(self):
|
|
21
|
+
return {
|
|
22
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
23
|
+
"Content-Type": "application/json"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def send_event(self, event_type, payload):
|
|
27
|
+
url = f"{self.ingest_url}/events"
|
|
28
|
+
data = {"type": event_type, "payload": payload}
|
|
29
|
+
for attempt in range(self.max_retry):
|
|
30
|
+
try:
|
|
31
|
+
resp = requests.post(url, json=data, headers=self._headers(), timeout=5)
|
|
32
|
+
if resp.status_code == 200:
|
|
33
|
+
log("Event sent successfully", self.debug)
|
|
34
|
+
return True
|
|
35
|
+
except Exception as e:
|
|
36
|
+
log(f"Send event failed: {e}", self.debug)
|
|
37
|
+
time.sleep(1)
|
|
38
|
+
return False
|
|
39
|
+
|
|
40
|
+
def _heartbeat_loop(self):
|
|
41
|
+
url = f"{self.ingest_url}/heartbeat"
|
|
42
|
+
while not self._stop_event.is_set():
|
|
43
|
+
try:
|
|
44
|
+
resp = requests.post(url, headers=self._headers(), timeout=5)
|
|
45
|
+
log(f"Heartbeat sent: {resp.status_code}", self.debug)
|
|
46
|
+
except Exception as e:
|
|
47
|
+
log(f"Heartbeat failed: {e}", self.debug)
|
|
48
|
+
time.sleep(self.heartbeat_interval)
|
|
49
|
+
|
|
50
|
+
def start(self):
|
|
51
|
+
log("Starting heartbeat...", self.debug)
|
|
52
|
+
self._stop_event.clear()
|
|
53
|
+
self._thread = threading.Thread(target=self._heartbeat_loop, daemon=True)
|
|
54
|
+
self._thread.start()
|
|
55
|
+
|
|
56
|
+
def stop(self):
|
|
57
|
+
log("Stopping heartbeat...", self.debug)
|
|
58
|
+
self._stop_event.set()
|
|
59
|
+
if self._thread:
|
|
60
|
+
self._thread.join()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import queue
|
|
2
|
+
import threading
|
|
3
|
+
import requests
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
class EventQueue(threading.Thread):
|
|
7
|
+
def __init__(self, config):
|
|
8
|
+
super().__init__(daemon=True)
|
|
9
|
+
self.config = config
|
|
10
|
+
self.events = queue.Queue()
|
|
11
|
+
self._stop_event = threading.Event()
|
|
12
|
+
|
|
13
|
+
def add_event(self, event_type, payload):
|
|
14
|
+
self.events.put({"type": event_type, "payload": payload})
|
|
15
|
+
|
|
16
|
+
def run(self):
|
|
17
|
+
while not self._stop_event.is_set():
|
|
18
|
+
try:
|
|
19
|
+
event = self.events.get(timeout=1)
|
|
20
|
+
requests.post(
|
|
21
|
+
f"{self.config.ingest_url}/event",
|
|
22
|
+
json={"api_key": self.config.api_key, **event},
|
|
23
|
+
timeout=5
|
|
24
|
+
)
|
|
25
|
+
except queue.Empty:
|
|
26
|
+
continue
|
|
27
|
+
except Exception as e:
|
|
28
|
+
print(f"[Secploy] Event send error: {e}")
|
|
29
|
+
time.sleep(2)
|
|
30
|
+
|
|
31
|
+
def stop(self):
|
|
32
|
+
self._stop_event.set()
|
|
33
|
+
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import threading
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
class HeartbeatThread(threading.Thread):
|
|
6
|
+
def __init__(self, config, interval=30):
|
|
7
|
+
super().__init__(daemon=True)
|
|
8
|
+
self.config = config
|
|
9
|
+
self.interval = interval
|
|
10
|
+
self._stop_event = threading.Event()
|
|
11
|
+
|
|
12
|
+
def run(self):
|
|
13
|
+
while not self._stop_event.is_set():
|
|
14
|
+
try:
|
|
15
|
+
requests.post(
|
|
16
|
+
f"{self.config.ingest_url}/heartbeat",
|
|
17
|
+
json={"api_key": self.config.api_key, "status": "running"},
|
|
18
|
+
timeout=5
|
|
19
|
+
)
|
|
20
|
+
except Exception as e:
|
|
21
|
+
print(f"[Secploy] Heartbeat error: {e}")
|
|
22
|
+
time.sleep(self.interval)
|
|
23
|
+
|
|
24
|
+
def stop(self):
|
|
25
|
+
self._stop_event.set()
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: secploy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Secploy security monitoring and event tracking
|
|
5
|
+
Author-email: Abdulsamad Abdulganiyu <agastronics@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 AGASTRONICS
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Requires-Python: >=3.7
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: requests>=2.20.0
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="https://secploy.vercel.app/logo.png" alt="Secploy Logo" width="180">
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<h1 align="center">Secploy Python SDK</h1>
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<em>Event tracking, heartbeat monitoring, and real-time status updates for your apps β powered by Secploy.</em>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## π Overview
|
|
47
|
+
|
|
48
|
+
**Secploy** is a modern **security monitoring and observability platform** that helps you track **events, uptime, and live statuses** in real time.
|
|
49
|
+
|
|
50
|
+
With the **Secploy Python SDK**, you can:
|
|
51
|
+
- β
Send **events** from your Python applications or microservices.
|
|
52
|
+
- π Monitor uptime & availability using **heartbeats**.
|
|
53
|
+
- π Attach **environment** and **project metadata** automatically.
|
|
54
|
+
- π‘ Receive **live project statuses** in your Secploy dashboard (`Running`, `Idle`, `Shutdown`).
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## π Installation
|
|
59
|
+
|
|
60
|
+
Install directly from **PyPI**:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install secploy
|
|
64
|
+
````
|
|
65
|
+
|
|
66
|
+
Or from source:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
git clone https://github.com/your-org/secploy-python-sdk.git
|
|
70
|
+
cd secploy-python-sdk
|
|
71
|
+
pip install .
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## β‘ Quick Start
|
|
77
|
+
|
|
78
|
+
### 1οΈβ£ Initialize the Client
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from secploy import SecployClient
|
|
82
|
+
|
|
83
|
+
client = SecployClient(
|
|
84
|
+
api_key="your_project_api_key",
|
|
85
|
+
environment="production"
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### 2οΈβ£ Send Events
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
client.track_event(
|
|
95
|
+
name="user_signup",
|
|
96
|
+
properties={
|
|
97
|
+
"user_id": 101,
|
|
98
|
+
"plan": "pro",
|
|
99
|
+
"referral": "campaign_2025"
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### 3οΈβ£ Report an Incident
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
incident = client.create_incident(
|
|
110
|
+
title="High Error Rate",
|
|
111
|
+
description="API error rate exceeded 5% in the EU region.",
|
|
112
|
+
severity="critical"
|
|
113
|
+
)
|
|
114
|
+
print("Incident ID:", incident.id)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### 4οΈβ£ Monitor Heartbeats
|
|
120
|
+
|
|
121
|
+
*(Ideal for background jobs, services, or scheduled tasks)*
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
import time
|
|
125
|
+
|
|
126
|
+
while True:
|
|
127
|
+
client.heartbeat()
|
|
128
|
+
time.sleep(60) # every minute
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### 5οΈβ£ Listen for Live Status Updates
|
|
134
|
+
|
|
135
|
+
*(Requires WebSocket + Django Channels backend)*
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
for status in client.listen_status():
|
|
139
|
+
print(f"[STATUS UPDATE] Project is now {status}")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Possible statuses:
|
|
143
|
+
|
|
144
|
+
* `running`
|
|
145
|
+
* `idle`
|
|
146
|
+
* `shutdown`
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## π Environments
|
|
151
|
+
|
|
152
|
+
When you create a project in Secploy, multiple environments are automatically created:
|
|
153
|
+
|
|
154
|
+
| Environment | Purpose |
|
|
155
|
+
| ------------- | ---------------------- |
|
|
156
|
+
| `production` | Live, customer-facing |
|
|
157
|
+
| `staging` | Pre-production testing |
|
|
158
|
+
| `development` | Local development |
|
|
159
|
+
|
|
160
|
+
Each environment has its own **API key** β use the matching key for the environment youβre sending data from.
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## π‘ SDK Methods
|
|
165
|
+
|
|
166
|
+
| Method | Description |
|
|
167
|
+
| ----------------------------------------------- | ------------------------------ |
|
|
168
|
+
| `track_event(name, properties)` | Send a structured event |
|
|
169
|
+
| `create_incident(title, description, severity)` | Create a new incident |
|
|
170
|
+
| `heartbeat()` | Send a heartbeat signal |
|
|
171
|
+
| `listen_status()` | Stream live project status |
|
|
172
|
+
| `set_environment(env_code)` | Switch environment dynamically |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## π‘ Requirements
|
|
177
|
+
|
|
178
|
+
* Python **3.8+**
|
|
179
|
+
* `requests`
|
|
180
|
+
* `websocket-client`
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## π€ Contributing
|
|
185
|
+
|
|
186
|
+
1. Fork the repo
|
|
187
|
+
2. Create your feature branch:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
git checkout -b feature/my-feature
|
|
191
|
+
```
|
|
192
|
+
3. Commit your changes:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
git commit -m "Add my feature"
|
|
196
|
+
```
|
|
197
|
+
4. Push to the branch and open a Pull Request
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## π License
|
|
202
|
+
|
|
203
|
+
MIT License β See [LICENSE](LICENSE) for details.
|
|
204
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.cfg
|
|
6
|
+
./secploy/__init__.py
|
|
7
|
+
./secploy/client.py
|
|
8
|
+
./secploy/config.py
|
|
9
|
+
./secploy/events.py
|
|
10
|
+
./secploy/exceptions.py
|
|
11
|
+
./secploy/heartbeat.py
|
|
12
|
+
./secploy/utils.py
|
|
13
|
+
secploy/__init__.py
|
|
14
|
+
secploy/client.py
|
|
15
|
+
secploy/config.py
|
|
16
|
+
secploy/events.py
|
|
17
|
+
secploy/exceptions.py
|
|
18
|
+
secploy/heartbeat.py
|
|
19
|
+
secploy/utils.py
|
|
20
|
+
secploy.egg-info/PKG-INFO
|
|
21
|
+
secploy.egg-info/SOURCES.txt
|
|
22
|
+
secploy.egg-info/dependency_links.txt
|
|
23
|
+
secploy.egg-info/requires.txt
|
|
24
|
+
secploy.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.20.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
secploy
|