ventro-minecraft-status 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.
- ventro_minecraft_status-1.0.0/LICENSE +9 -0
- ventro_minecraft_status-1.0.0/PKG-INFO +37 -0
- ventro_minecraft_status-1.0.0/README.md +20 -0
- ventro_minecraft_status-1.0.0/pyproject.toml +24 -0
- ventro_minecraft_status-1.0.0/setup.cfg +4 -0
- ventro_minecraft_status-1.0.0/tests/test_status.py +62 -0
- ventro_minecraft_status-1.0.0/ventro_minecraft_status/__init__.py +62 -0
- ventro_minecraft_status-1.0.0/ventro_minecraft_status/py.typed +0 -0
- ventro_minecraft_status-1.0.0/ventro_minecraft_status.egg-info/PKG-INFO +37 -0
- ventro_minecraft_status-1.0.0/ventro_minecraft_status.egg-info/SOURCES.txt +10 -0
- ventro_minecraft_status-1.0.0/ventro_minecraft_status.egg-info/dependency_links.txt +1 -0
- ventro_minecraft_status-1.0.0/ventro_minecraft_status.egg-info/top_level.txt +1 -0
|
@@ -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,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,20 @@
|
|
|
1
|
+
# ventro-minecraft-status
|
|
2
|
+
|
|
3
|
+
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+.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from ventro_minecraft_status import status, badge_url, StatusError
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
s = status("play.example.com") # SRV records are resolved, "host:port" works too
|
|
10
|
+
print(s["online"], s["players"], s["max"], s["version"], s["latencyMs"])
|
|
11
|
+
print(s["motdText"])
|
|
12
|
+
except StatusError as e:
|
|
13
|
+
print(e.reason, e) # invalid, dns, port, blocked, rate, network ...
|
|
14
|
+
|
|
15
|
+
print(badge_url("play.example.com")) # https://ventrohosting.com/badge/play.example.com.svg
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The API limits requests per visitor. Cache the result and do not poll more than once a minute.
|
|
19
|
+
|
|
20
|
+
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,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ventro-minecraft-status"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Minecraft Java server status (online, players, version, MOTD, latency) from the free VentroHosting API. No dependencies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "VentroHosting", email = "info@ventrohosting.com" }]
|
|
13
|
+
keywords = ["minecraft", "server-status", "minecraft-server", "ping", "motd", "status-badge"]
|
|
14
|
+
classifiers = ["License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Typing :: Typed"]
|
|
15
|
+
|
|
16
|
+
[project.urls]
|
|
17
|
+
Homepage = "https://ventrohosting.com/tools/minecraft-server-status"
|
|
18
|
+
Source = "https://github.com/ventrohosting/ventro-minecraft-status-python"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools]
|
|
21
|
+
packages = ["ventro_minecraft_status"]
|
|
22
|
+
|
|
23
|
+
[tool.setuptools.package-data]
|
|
24
|
+
ventro_minecraft_status = ["py.typed"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import unittest
|
|
5
|
+
import urllib.error
|
|
6
|
+
|
|
7
|
+
from ventro_minecraft_status import StatusError, badge_url, status
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Res:
|
|
11
|
+
def __init__(self, body, code=200):
|
|
12
|
+
self.status = code
|
|
13
|
+
self._b = json.dumps(body).encode()
|
|
14
|
+
|
|
15
|
+
def read(self):
|
|
16
|
+
return self._b
|
|
17
|
+
|
|
18
|
+
def __enter__(self):
|
|
19
|
+
return self
|
|
20
|
+
|
|
21
|
+
def __exit__(self, *a):
|
|
22
|
+
return False
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class T(unittest.TestCase):
|
|
26
|
+
def test_success_sends_address(self):
|
|
27
|
+
seen = {}
|
|
28
|
+
|
|
29
|
+
def op(req, timeout=None):
|
|
30
|
+
seen["url"] = req.full_url
|
|
31
|
+
return Res({"ok": True, "online": True, "players": 3})
|
|
32
|
+
|
|
33
|
+
r = status("play.example.com:25566", opener=op)
|
|
34
|
+
self.assertEqual(r["players"], 3)
|
|
35
|
+
self.assertTrue(seen["url"].endswith("/api/tools/minecraft-status?adresse=play.example.com%3A25566"))
|
|
36
|
+
|
|
37
|
+
def test_http_error(self):
|
|
38
|
+
def op(req, timeout=None):
|
|
39
|
+
raise urllib.error.HTTPError(req.full_url, 429, "x", {}, io.BytesIO(json.dumps({"ok": False, "reason": "rate", "message": "Zu viele"}).encode()))
|
|
40
|
+
|
|
41
|
+
with self.assertRaises(StatusError) as c:
|
|
42
|
+
status("x", opener=op)
|
|
43
|
+
self.assertEqual((c.exception.reason, c.exception.status), ("rate", 429))
|
|
44
|
+
|
|
45
|
+
def test_network(self):
|
|
46
|
+
def op(req, timeout=None):
|
|
47
|
+
raise urllib.error.URLError("boom")
|
|
48
|
+
|
|
49
|
+
with self.assertRaises(StatusError) as c:
|
|
50
|
+
status("x", opener=op)
|
|
51
|
+
self.assertEqual(c.exception.reason, "network")
|
|
52
|
+
|
|
53
|
+
def test_badge(self):
|
|
54
|
+
self.assertEqual(badge_url("mc.example.com"), "https://ventrohosting.com/badge/mc.example.com.svg")
|
|
55
|
+
|
|
56
|
+
@unittest.skipIf(os.environ.get("OFFLINE") == "1", "offline")
|
|
57
|
+
def test_live(self):
|
|
58
|
+
self.assertIsInstance(status("mc.hypixel.net")["online"], bool)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
unittest.main()
|
|
@@ -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,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
tests/test_status.py
|
|
5
|
+
ventro_minecraft_status/__init__.py
|
|
6
|
+
ventro_minecraft_status/py.typed
|
|
7
|
+
ventro_minecraft_status.egg-info/PKG-INFO
|
|
8
|
+
ventro_minecraft_status.egg-info/SOURCES.txt
|
|
9
|
+
ventro_minecraft_status.egg-info/dependency_links.txt
|
|
10
|
+
ventro_minecraft_status.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ventro_minecraft_status
|