py-mine / mcstatus

A Python library for checking the status of Minecraft servers
https://mcstatus.readthedocs.io
Apache License 2.0
475 stars 37 forks source link

website alternative? #157

Open py-mine-bot opened 2 years ago

py-mine-bot commented 2 years ago

Aaronstar-McClure Authored by Aaronstar-McClure


so i see that dinnerbone's page is down because of a recapatcha issue. is anyone hosting a mirror or alternative web page?

py-mine-bot commented 2 years ago

kevinkjt2000 Authored by kevinkjt2000


Not that I'm aware of.

py-mine-bot commented 2 years ago

kevinkjt2000 Authored by kevinkjt2000


I'm looking at possibly using Brython to deploy a GitHub pages (or some other static site host) version of mcstatus. This would alleviate the need for running a server as a backend by running Python code directly in the web browser of the visitor. The issue is that not all Python code is supported, such as asyncio. Instead, there are other built-in async functions that are mostly identical, so this may be tricky to do. The cost of running a backend server and the time involved to set one up in a serverless environment has deterred me thus far, so Brython seems promising and therefore possibly worth the effort. No ETA on when I'll have something working, but I am tinkering with this.

PerchunPak commented 2 years ago

Maybe close this? There are CLI part and interpreter interactive session for investigating API.

kevinkjt2000 commented 2 years ago

A handful of people believe Dinnerbone used this repo to deploy his website. While this confusion might be less likely to happen now that mcstatus is in an organization, I would still like to leave it open for this reason and ...

I still see deploying to a web browser as convenient for some users. Imagine installing Python is a barrier for some and being on mobile would make using mcstatus tricky too. It is low-priority work, because I am waiting for something that supports async Python (or an expert on porting Python to web to swoop in and do it). Web assembly keeps gaining traction, and someone could make a Python interpreter or compiler that supports mcstatus someday.

ItsDrike commented 2 years ago

Web assembly keeps gaining traction, and someone could make a Python interpreter or compiler that supports mcstatus someday.

Actually, WA interpreter for python is already a thing, because of RustPyhon. It's a python compiler written in rust, and rust can be compiled into web assembly. It's a pretty cool project, but it's still in beta: https://github.com/RustPython/RustPython

For now, it certainly not work with our codebase, as from my testing, even basic asyncio or sockets didn't seem to work, as some of the standard library tooling that requires implementation specific logic just isn't there yet. But that's to be expected considering the WIP status of this project, however it could be something to keep an eye on and once more language features are actually supported, this might just be the way to go about this.

They do have a demo version where the compiler is already running in WA hosted on their github pages: https://rustpython.github.io/demo/

PerchunPak commented 1 year ago

Can we just write some API in FastAPI (or any another framework) and then frontend for it? Like alternative for https://mcstatus.io and https://mcsrvstat.us?

ItsDrike commented 1 year ago

We absolutely could, but I'm pretty sure we can't host that on GitHub pages. We'd need something else and I'm not sure how willing we are to invest into a VPS just for mcstatus. The alternative would be to use some of the free hosting services, which have their own issues, but it would certainly be doable.

PerchunPak commented 1 year ago

Well, VPS is not so expensive. I have 3 VPSes for ~$1.4 each of them (1 shared vCPU core, 8gb RAM and 20gb SSD). They are excellent for their price.

Although, if we will have many people that want to use us, it would be much more expensive to host. But why just not just buy more VPSes instead of better ones?)

ItsDrike commented 1 year ago

I'm aware of the prices, that's not the biggest issue. The much bigger concern that I have is the other annoyances that come with this. Things like managing the VPS long term, keeping things secure and up to date, but also the fact that a VPS like this would ideally need to be shared between all maintainers, and it's just quite a fair bit of work to set everything up and keeping it working.

I would honestly much rather see a 3rd party site be created that uses mcstatus under the hood, which we could maybe even link to from here. I was actually considering making such site myself a while ago, but I never got to it. If this 3rd party site would then get popular enough, it could even move under the py-mine org's umbrella.

As to handling this from this repository, the best possibility I see is to go with github pages, but those don't allow running full backend servers like fastAPI (afaik). This is why we were talking about WebAssembly based version, which could actually run the python code itself in the browser, making it easy enough to maintain for us directly from here.

PerchunPak commented 1 year ago

I have just checked RustPython with our project in default GitHub codespace.

The .sh script to install Rust, RustPython, pip and mcstatus:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"

# from https://rustpython.github.io/blog/2021/01/26/pip-support.html
cargo install --git https://github.com/RustPython/RustPython --features ssl
curl https://bootstrap.pypa.io/get-pip.py -O
rustpython get-pip.py

rustpython -m pip install mcstatus

And the output of the try:

$ rustpython
Welcome to the magnificent Rust Python 0.2.0 interpreter 😱 🖖
No previous history.
>>>>> import mcstatus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/mcstatus/mcstatus/__init__.py", line 1, in <module>
    from mcstatus.server import BedrockServer, JavaServer, MCServer  # noqa: F401
  File "/workspaces/mcstatus/mcstatus/server.py", line 7, in <module>
    import dns.resolver
  File "/home/codespace/.local/lib/rustpython3.11/site-packages/dns/resolver.py", line 36, in <module>
    import dns.message
  File "/home/codespace/.local/lib/rustpython3.11/site-packages/dns/message.py", line 24, in <module>
    import dns.wire
  File "/home/codespace/.local/lib/rustpython3.11/site-packages/dns/wire.py", line 7, in <module>
    import dns.name
  File "/home/codespace/.local/lib/rustpython3.11/site-packages/dns/name.py", line 33, in <module>
    import dns.immutable
  File "/home/codespace/.local/lib/rustpython3.11/site-packages/dns/immutable.py", line 9, in <module>
    from dns._immutable_ctx import immutable
  File "/home/codespace/.local/lib/rustpython3.11/site-packages/dns/_immutable_ctx.py", line 11, in <module>
    _in__init__ = contextvars.ContextVar('_immutable_in__init__', default=False)
RuntimeError: Expected payload 'ContextVar' but 'ContextVar' found

So the import crashes because of unimplemented PEP 567, they have an issue for this - https://github.com/RustPython/RustPython/issues/3188. So looks like this issue is blocked by it.


P.S. I found, that FastAPI's sponsor Deta.cloud proposes free hosting for FastAPI (and not only) applications, also Vercel can propose free hosting for frontend. This frees us from spending any money and additional efforts on managing all the things, so we need to spend time only on writing code. Although, if there will be many users, we possibly need to use some CDN to cache answers (CloudFlare free plan?).

As backend is a task for a few minutes (dataclasses, that were introduced in #306, can be easily transformed to JSON by dataclasses.asdict. Only the query answer object needs to be somehow processed, but I think transforming it to dataclass would be a better and faster idea), someone just needs to write frontend and the analogue for mcstatus.io and mcsrvstat.us is ready.

This, of course, will not give an interactive shell, but would be a much more stable decision, as RustPython is still in beta, and looks like, it will be there for a long time.

kevinkjt2000 commented 1 year ago

Frontend static hosting is not a concern of mine. GitHub pages and many other free hosts can fit that.

My trepidations are for running a backend. I don't want to maintain, secure, or deal with setting up a backend. While I know how to do all those things, they all cost both time and money to do them well and right. So, I would prefer a Python runtime that could embed into the user's web browser to run the code.

PerchunPak commented 1 year ago

So I wrote simple backend in FastAPI and deployed it to Deta in half a hour. Although this all needs to be automaticated (to deploy, you need to write space push), all the proccess is easy.

https://mcstatus-fastapi.perchun.it/status/hypixel.net

PerchunPak commented 1 year ago

Oops, their apps are private by default, I have made it public now.

kevinkjt2000 commented 1 year ago

Reiterating this stuff is not complicated, I still do not want to be on the hook for maintaining, securing, and hosting it. Those backends have to receive regular updates in order to select newer versions of Python when security fixes are released. Going to have to enable CORS on the API to handle another domain referencing it in the web browser. And whatever else I'm forgetting from the last time I deployed a serverless application that had a split backend/frontend.

PerchunPak commented 1 year ago

Well, while you do not like to maintain this, I can. It's not necessarily that we all will maintain this all.

I still see backend as a few files of code, which in most, are just models for not returning redundant data and wrapping mcstatus itself. If someone wants to write frontend - we can start it right now (although it would be great to hear ItsDrike's mind too).

ItsDrike commented 1 year ago

I fully agree with Kevin on this, I brought up sinilar concerns that Kevin mentioned in my earlier message too. I'm aware that making the API or even a full website wouldn't be particularly hard, but this repository isn't the place for such a website. The only acceptable solution when it comes to websites that I see is the static approach, with github pages.

Not to mention that setting up and maintaining a server, while not that difficult either is simply not something I want to have to think about as one of the responsibilities of mcstatus maintainers.

As for external projects, obviously, you can do anything you like. And I fully encourage you to, working with FastAPI, or something like Sanic or perhaps Flask can be fun, and if you feel like it, you can certainly go ahead with it.

If the project gets to some meaningful state, we might even mention it in the readme, and it can perhaps be transferred under the py-mine organization eventually.

All that said, again, as an issue opened on this repo, being about adding a website for mcstatus here, I don't see that happening with any active backends.

PerchunPak commented 1 year ago

As for external projects, obviously, you can do anything you like. And I fully encourage you to, working with FastAPI, or something like Sanic or perhaps Flask can be fun, and if you feel like it, you can certainly go ahead with it.

I know that the license allows me almost everything (even this), but I do not know frontend and I do not plan to learn it soon. So if some frontend dev is interested in this, they can email or DM me in Discord (you will find the links on my site).