Show HN: Mountaineer – Webapps in Python and React (github.com)
I’ve written a good 25+ webapps over the last few years in almost every major framework under the sun. Python and React remain my favorite. They let you get started quickly and grow to scale. But the developer experience of linking these two worlds remains less than optimal:
— Sharing typehints and schemas across frontend and backend code
— Scattered fetch() calls to template data and modify server objects
— Server side rendering / gateway support
— Error handling on frontend fetches
Mountaineer is an attempt to solve those problems. I didn’t want to re-invent the wheel of what Python and React are good at, so it’s relatively light on syntax. It provides one frontend hook for React apps and introduces a MVC convention on the backend for managing views. Support files are generated progressively through a local watcher, so IDE type-hints and function calls work out of the box.
It’s more intuitive to explain with some code, so pop over to the Github if you’re interested in this stack and taking a look:
Github: https://github.com/piercefreeman/mountaineer
More context: https://freeman.vc/notes/mountaineer-v01-webapps-in-python-a...
Would love to hear your thoughts!
60 comments
[ 3.3 ms ] story [ 155 ms ] threadhttps://www.reddit.com/r/litestarapi/comments/16flco9/core_m...
https://github.com/litestar-org/litestar/commits?author=Gold...
btw, to complete the astroturfing, falcon is still the sanest python web library by a longshot (constructing a controller using init and wiring it manually? heresy, must use some bullcrap fake DI system), but it's completely ignored by almost everyone (and maybe dead-ish).
If your Python is slow, you are probably doing it wrong.
I prefer fast prototyping over speed. Easier to fix the speed later, than never getting of ground with a “fast” language.
Edit:
Python 3.5 is where type hints were introduced, this was released in 2015, so nearly 9 years ago.
For example, `TypedDict` didn't support optional keys until Python 3.11, and even then you have to use the clunky `NotRequired` type to pull it off. This is despite the fact that having optional kwargs has been a common pattern for decades.
The type system is also not particularly robust. You can't make a class similar to `dataclasses.dataclass` yourself and have it typecheck propertly, so libraries like Pydantic have to develop custom plugins for typecheckers like mypy to get themselves to work.
I'll be honest, I have not used it extensively, I'm used to just doing Python the old way, maybe once its been fully refined and becomes the status quo I'll dive into it. Until then, if I want types I just use a typed language.
Just a personal opinion though, I'm always glad when people create something new and useful to them.
Was für den einen die Eule ist, ist für den anderen eine Nachtigall.
And maybe idiomatically in English:
One person's own is another person's nightingale. The owl is seen as bad luck while the nightingale as good luck.
I keep starting to build tic tac to application and then just leave it there.
Any tips and or documents on how to properly learn react ?
You'll want to use Django rest framework rather than straight Django, though. Have fun!
You can make a little tic-tac-toe game that runs in your browser using just React -- no need for Django, provided you don't want to save the state of the game to a database or something.
If I wanted to start today, I'd make sure I had Node 20.x installed, and then run `npm create vite@latest`. I'd name my project `tictac`, then select both `React` and `TypeScript`. I'd follow the instructions I get and visit the running React app in my browser at http://localhost:5173/.
From there, you can edit `src/App.tsx`. Make a tiny change, save it, and your browser will update immediately. I'd probably build my whole tic tac toe game right there in that single file.
TypeScript is optional but it's useful to learn and won't add too much complexity for this particular project (you can mostly ignore it if you like).
Once you have some basic comfort with these tools, the next question will be: okay, how can you make the code you just wrote talk to a Django server? A simple answer might be: have your code call out to the Django server by making a fetch() call. You'll have to figure out where, exactly, fetch() calls belong in React-using code. And you’ll want to have your Django server return some JSON (from a view) that your javascript code does something with. For this to work on your development machine, you'll run both the Vite server and the Django server at the same time. (npm run dev; python manage.py runserver).
A really tiny Django view should do just fine to start -- your goal is just to make sure the data sent by the Django server is received by your javascript code. After that, you can start to get fancy. You do not need Django Rest Framework, Ninja, or any other extension to Django on day one -- plain old Django is quite capable of sending and receiving JSON data. (Someday later, you might consider one of those add-ons, but I'd stick with the basics first.)
Maybe remove the .DS_Store files from repo and update your gitignore globally to avoid this issue. Also, Pydantic has SecretStr that might be useful to use.
(In an old commit and stripped out from the current codebase until it has better test coverage and the main codebase is stable)
Personally, I probably won't venture to use this as I don't really need the extra client-side flexibility that this provides, but it's an impressive project for an early stage release.
There have been several other web app packages highlighted here over the last week. It's great to see new work being done on open source hobby projects on the web app front for Python/react/rust.
By the way, I have been able to integrate JavaScript and any backend language with a hybrid approach, which works really well for large-scale commercial projects.
In a hybrid application, we'll have all of the following types of pages:
-- Server-first Django/Laravel/Ruby pages with little-to-no JavaScript.
-- Client-first JavaScript pages with little-to-no Django/Laravel/Ruby.
More Details Here ... https://twitter.com/dvcoolarun/status/1753310384843337907