py-connect-test 2.2.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.
File without changes
@@ -0,0 +1,51 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+
5
+ import typer
6
+
7
+ from py_connect_test.services.http import HttpTest
8
+ from py_connect_test.setup_logger import setup_logger
9
+
10
+ app = typer.Typer(help="Http Connection Test")
11
+
12
+ logger = setup_logger()
13
+
14
+
15
+ @app.callback(invoke_without_command=True)
16
+ def callback(ctx: typer.Context) -> None:
17
+ if ctx.invoked_subcommand is None:
18
+ typer.echo(ctx.get_help())
19
+ sys.exit(0)
20
+
21
+
22
+ @app.command()
23
+ def test(
24
+ insecure: bool = typer.Option(
25
+ False,
26
+ "-i",
27
+ "--insecure",
28
+ help="Bypass Certificate Checking",
29
+ ),
30
+ alerts: bool = typer.Option(
31
+ False,
32
+ "-a",
33
+ "--alerts",
34
+ help="Send Alert to Webhook (WEBHOOK_URL env variable)",
35
+ ),
36
+ ):
37
+ http_test = HttpTest(insecure=insecure)
38
+ status_code = http_test.get_status_code()
39
+ logger.success("Connected: {}", status_code)
40
+
41
+ if alerts:
42
+ alert = http_test.post_alerts()
43
+ logger.success("Alert response: {}", alert.status_code)
44
+
45
+
46
+ def main() -> None:
47
+ app()
48
+
49
+
50
+ if __name__ == "__main__":
51
+ main()
File without changes
@@ -0,0 +1,54 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+
5
+ import httpx
6
+
7
+ from py_connect_test.settings import AlertSettings, HttpSettings
8
+ from py_connect_test.setup_logger import setup_logger
9
+
10
+ logger = setup_logger()
11
+
12
+
13
+ class HttpTest:
14
+ def __init__(self, insecure: bool) -> None:
15
+ self.http_settings = HttpSettings()
16
+ self.alert_settings = AlertSettings()
17
+ self.insecure = insecure
18
+
19
+ def get(self) -> httpx.Response | None:
20
+ with httpx.Client(
21
+ base_url=self.http_settings.url,
22
+ verify=not self.insecure,
23
+ follow_redirects=True,
24
+ ) as client:
25
+ logger.info("Connecting to {}", self.http_settings.url)
26
+ try:
27
+ response = client.get("/")
28
+ response.raise_for_status()
29
+ return response
30
+ except httpx.RequestError as e:
31
+ logger.error("Error connecting to {}: {}", self.http_settings.url, e)
32
+ return None
33
+
34
+ def get_status_code(self) -> int | None:
35
+ response = self.get()
36
+ if not response:
37
+ return None
38
+ return response.status_code
39
+
40
+ def post_alerts(self) -> httpx.Response:
41
+ with open(self.alert_settings.payload_file_path) as f:
42
+ payload = json.load(f)
43
+
44
+ with httpx.Client(
45
+ base_url=self.alert_settings.webhook_url,
46
+ verify=not self.insecure,
47
+ ) as client:
48
+ response = client.post("/", json=payload)
49
+ response.raise_for_status()
50
+ logger.success(
51
+ "Alert posted successfully to {}",
52
+ self.alert_settings.webhook_url,
53
+ )
54
+ return response
@@ -0,0 +1,12 @@
1
+ from pydantic_settings import BaseSettings, SettingsConfigDict
2
+
3
+
4
+ class HttpSettings(BaseSettings):
5
+ model_config = SettingsConfigDict(env_prefix="PY_CONNECT_TEST_")
6
+
7
+ url: str = "https://ifconfig.me"
8
+
9
+
10
+ class AlertSettings(BaseSettings):
11
+ webhook_url: str = "http://prometheus.local"
12
+ payload_file_path: str = "payload.json"
@@ -0,0 +1,14 @@
1
+ import sys
2
+
3
+ import loguru
4
+ from loguru import logger
5
+
6
+
7
+ def setup_logger() -> loguru.Logger:
8
+ logger.remove()
9
+ logger.add(
10
+ sink=sys.stdout,
11
+ format="{time:YYYY-MM-DD HH:mm:ss} - {level} - {message}",
12
+ level="INFO",
13
+ )
14
+ return logger
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: py_connect_test
3
+ Version: 2.2.0
4
+ Summary: A simple Python package for testing connectivity.
5
+ License: MIT
6
+ Keywords: python3
7
+ Author: Victor Bajada
8
+ Author-email: bajada.victor@gmail.com
9
+ Maintainer: Victor Bajada
10
+ Maintainer-email: bajada.victor@gmail.com
11
+ Requires-Python: >=3.14,<4.0
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: Implementation :: CPython
23
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
24
+ Classifier: Typing :: Typed
25
+ Requires-Dist: httpx (>=0.28.1,<0.29.0)
26
+ Requires-Dist: loguru (>=0.7.0,<0.8.0)
27
+ Requires-Dist: pydantic-settings (>=2.14.1,<3.0.0)
28
+ Requires-Dist: rich (>=14.0.0,<15.0.0)
29
+ Requires-Dist: typer (>=0.25.0,<0.26.0)
30
+ Project-URL: Changelog, https://github.com/Diapolo10/project-name/blob/main/CHANGELOG.md
31
+ Project-URL: Documentation, https://github.com/tech1ndex/py-connect-test/tree/main/docs
32
+ Project-URL: Homepage, https://pypi.org/project/py-connect-test/
33
+ Project-URL: Repository, https://github.com/tech1ndex/py-connect-test
34
+ Project-URL: Tracker, https://github.com/Diapolo10/project-name/issues
35
+ Description-Content-Type: text/markdown
36
+
37
+ # py-connect-test
38
+
39
+ A simple Python package to test HTTP connectivity to URLs and retrieve status codes. Built with Typer CLI framework and httpx.
40
+
41
+ ## Prerequisites
42
+
43
+ - Python 3.14 or higher
44
+ - Poetry (for dependency management)
45
+
46
+ ## Installation
47
+
48
+ ### From Source
49
+
50
+ ```bash
51
+ git clone https://github.com/tech1ndex/py-connect-test.git
52
+ cd py-connect-test
53
+ poetry install
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ### Basic Usage
59
+
60
+ Test connectivity to the default URL (https://ifconfig.me):
61
+
62
+ ```bash
63
+ poetry run py-connect-test test
64
+ ```
65
+
66
+ Or directly:
67
+
68
+ ```bash
69
+ python -m py_connect_test.main test
70
+ ```
71
+
72
+ ### Options
73
+
74
+ #### Bypass SSL Certificate Validation
75
+
76
+ ```bash
77
+ poetry run py-connect-test test --insecure
78
+ # or
79
+ poetry run py-connect-test test -i
80
+ ```
81
+
82
+ #### Send Alerts to Webhook
83
+
84
+ ```bash
85
+ poetry run py-connect-test test --alerts
86
+ # or
87
+ poetry run py-connect-test test -a
88
+ ```
89
+
90
+ #### Combined Options
91
+
92
+ ```bash
93
+ poetry run py-connect-test test --insecure --alerts
94
+ ```
95
+
96
+ ### View Help
97
+
98
+ ```bash
99
+ poetry run py-connect-test test --help
100
+ ```
101
+
102
+ ## Docker Usage
103
+
104
+ ### Build Image
105
+
106
+ ```bash
107
+ docker build -t py-connect-test:latest .
108
+ ```
109
+
110
+ ### Run Container
111
+
112
+ ```bash
113
+ docker run -d \
114
+ -e HTTP_URL=https://example.com \
115
+ -e WEBHOOK_URL=http://prometheus.local \
116
+ ghcr.io/tech1ndex/py-connect-test:latest
117
+ ```
118
+
119
+ ### Bypass SSL Validation
120
+
121
+ ```bash
122
+ docker run -d \
123
+ -e PY_CONNECT_TEST_URL=https://example.com \
124
+ ghcr.io/tech1ndex/py-connect-test:latest \
125
+ py-connect-test test --insecure
126
+ ```
127
+
128
+ ### Multi-Architecture Support
129
+
130
+ Available architectures:
131
+ - `amd64`
132
+ - `arm64`
133
+
134
+ Pull specific architecture:
135
+
136
+ ```bash
137
+ docker pull ghcr.io/tech1ndex/py-connect-test:latest-amd64
138
+ docker pull ghcr.io/tech1ndex/py-connect-test:latest-arm64
139
+ ```
140
+
141
+ ## Environment Variables
142
+
143
+ | Variable | Description | Default | Required |
144
+ |-----------------------|-------------|---------|----------|
145
+ | `PY_CONNECT_TEST_URL` | URL to test connectivity to | `https://ifconfig.me` | No |
146
+ | `WEBHOOK_URL` | Webhook URL for alerts | `http://prometheus.local` | No |
147
+ | `PAYLOAD_FILE_PATH` | Path to JSON payload file for webhooks | `/tmp/payload.json` | No |
148
+
149
+
150
+ ## Project Structure
151
+
152
+ ```
153
+ py-connect-test/
154
+ ├── src/py_connect_test/
155
+ │ ├── main.py # CLI entry point
156
+ │ ├── settings.py # Configuration management
157
+ │ ├── setup_logger.py # Logger setup
158
+ │ ├── py.typed # Type hints marker
159
+ │ └── services/
160
+ │ └── http.py # HTTP service
161
+ ├── tests/
162
+ │ ├── conftest.py # Pytest fixtures
163
+ │ └── services/
164
+ │ └── test_http_service.py # HTTP service tests
165
+ ├── pyproject.toml # Project configuration
166
+ ├── Dockerfile # Docker configuration
167
+ └── README.md
168
+ ```
169
+
@@ -0,0 +1,10 @@
1
+ py_connect_test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ py_connect_test/main.py,sha256=gY3WdeDj_9azk9_uyQruM8vKtPrGK1eqqvf1Qc7XKbU,1073
3
+ py_connect_test/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ py_connect_test/services/http.py,sha256=y5DHG9R6RixJBr_FiXjBQEieE5dy9t8Km-zVFqimtgk,1679
5
+ py_connect_test/settings.py,sha256=mBQ3Pu2LlOJ9oHOiUGoS0gJGt81LTjRLabBMk9ldbOM,336
6
+ py_connect_test/setup_logger.py,sha256=LRfw2ghm1-k2eBMqOpKJpcdm3AZIOCfgc8KikEHVhUc,265
7
+ py_connect_test-2.2.0.dist-info/METADATA,sha256=N6FdpZyJfw2ooZ5n6sKstUxCphLfO9Uj6Um1CX0SaxA,4386
8
+ py_connect_test-2.2.0.dist-info/WHEEL,sha256=EGEvSphFYqXKs23-kQBeyNoJP1nrT8ZJKQoi5p5DYL8,88
9
+ py_connect_test-2.2.0.dist-info/entry_points.txt,sha256=zwYyTMK5baBWaYJfoQCCO2x6fIA0b3e09Rc2X7026kA,60
10
+ py_connect_test-2.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.4.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ py_connect_test=py_connect_test.main:app
3
+