ventro-minecraft-status 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,62 @@
1
+ """Client for the free Minecraft server status API of VentroHosting.
2
+
3
+ https://ventrohosting.com/tools/minecraft-server-status
4
+ """
5
+ from __future__ import annotations
6
+
7
+ import json
8
+ import urllib.error
9
+ import urllib.parse
10
+ import urllib.request
11
+ from typing import Any, Callable, Optional
12
+
13
+ __all__ = ["status", "badge_url", "StatusError", "__version__"]
14
+ __version__ = "1.0.0"
15
+
16
+ BASE_URL = "https://ventrohosting.com"
17
+
18
+
19
+ class StatusError(Exception):
20
+ """The API rejected the request or could not be reached. ``reason`` is e.g. invalid, dns, port, blocked, rate, network."""
21
+
22
+ def __init__(self, message: str, reason: str = "error", status: int = 0) -> None:
23
+ super().__init__(message)
24
+ self.reason = reason
25
+ self.status = status
26
+
27
+
28
+ def status(
29
+ address: str,
30
+ *,
31
+ base_url: str = BASE_URL,
32
+ timeout: float = 10.0,
33
+ opener: Optional[Callable[..., Any]] = None,
34
+ ) -> dict:
35
+ """Status of a Java Edition server: online, players, max, version, motdText, latencyMs, ...
36
+
37
+ ``address`` is ``host`` or ``host:port``; SRV records are resolved by the API.
38
+ The API limits requests per visitor, so cache results and do not poll faster than once a minute.
39
+ """
40
+ url = base_url.rstrip("/") + "/api/tools/minecraft-status?" + urllib.parse.urlencode({"adresse": str(address)})
41
+ req = urllib.request.Request(url, headers={"Accept": "application/json", "User-Agent": "ventro-minecraft-status-python/" + __version__})
42
+ open_ = opener or urllib.request.urlopen
43
+ try:
44
+ with open_(req, timeout=timeout) as res:
45
+ code = getattr(res, "status", 200)
46
+ body = json.loads(res.read().decode("utf-8"))
47
+ except urllib.error.HTTPError as e:
48
+ try:
49
+ body = json.loads(e.read().decode("utf-8"))
50
+ except Exception:
51
+ body = {}
52
+ raise StatusError(body.get("message") or "Status API error", body.get("reason") or "error", e.code) from None
53
+ except (urllib.error.URLError, OSError, ValueError) as e:
54
+ raise StatusError("Status API not reachable: %s" % e, "network", 0) from None
55
+ if not isinstance(body, dict) or body.get("ok") is not True:
56
+ raise StatusError((body or {}).get("message") or "Status API error", (body or {}).get("reason") or "error", code)
57
+ return body
58
+
59
+
60
+ def badge_url(address: str, base_url: str = BASE_URL) -> str:
61
+ """URL of the SVG status badge for an address."""
62
+ return base_url.rstrip("/") + "/badge/" + urllib.parse.quote(str(address), safe="") + ".svg"
File without changes
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: ventro-minecraft-status
3
+ Version: 1.0.0
4
+ Summary: Minecraft Java server status (online, players, version, MOTD, latency) from the free VentroHosting API. No dependencies.
5
+ Author-email: VentroHosting <info@ventrohosting.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://ventrohosting.com/tools/minecraft-server-status
8
+ Project-URL: Source, https://github.com/ventrohosting/ventro-minecraft-status-python
9
+ Keywords: minecraft,server-status,minecraft-server,ping,motd,status-badge
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: license-file
17
+
18
+ # ventro-minecraft-status
19
+
20
+ Check a Minecraft Java Edition server from Python: online or offline, players, version, MOTD and latency. It uses the free status API of [VentroHosting](https://ventrohosting.com/tools/minecraft-server-status). No dependencies, Python 3.8+.
21
+
22
+ ```python
23
+ from ventro_minecraft_status import status, badge_url, StatusError
24
+
25
+ try:
26
+ s = status("play.example.com") # SRV records are resolved, "host:port" works too
27
+ print(s["online"], s["players"], s["max"], s["version"], s["latencyMs"])
28
+ print(s["motdText"])
29
+ except StatusError as e:
30
+ print(e.reason, e) # invalid, dns, port, blocked, rate, network ...
31
+
32
+ print(badge_url("play.example.com")) # https://ventrohosting.com/badge/play.example.com.svg
33
+ ```
34
+
35
+ The API limits requests per visitor. Cache the result and do not poll more than once a minute.
36
+
37
+ Only the address you pass is sent to ventrohosting.com ([privacy policy](https://ventrohosting.com/datenschutz)). A browser version with a badge generator is on [ventrohosting.com/tools/minecraft-server-status](https://ventrohosting.com/tools/minecraft-server-status) (German). MIT licence.
@@ -0,0 +1,7 @@
1
+ ventro_minecraft_status/__init__.py,sha256=ZdeD8zaYWZZYhf7Y5LvlQf4Vpp7mytgoPGUsiKmtD3U,2499
2
+ ventro_minecraft_status/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ ventro_minecraft_status-1.0.0.dist-info/licenses/LICENSE,sha256=ElWpFzVoTU_dDzqXHIu0EJuYAx7i-A4xd7dWUbT5KX0,1070
4
+ ventro_minecraft_status-1.0.0.dist-info/METADATA,sha256=FiuxkfS7cxNG2gCh4HH36GGnCtWb0wdUVjILhWeRuxI,1888
5
+ ventro_minecraft_status-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ ventro_minecraft_status-1.0.0.dist-info/top_level.txt,sha256=Q89fROtKcjoDEjZ04Tgpcn0cFbBjAOianj9tSF0hE_s,24
7
+ ventro_minecraft_status-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 VentroHosting
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ ventro_minecraft_status