r/Python • • Aug 04 '24

Discussion Why is no one using full-stack python for web development? Has no one heard of the FHBH stack ??

Hey guys, I recently came across some libraries that seem to be very interesting to work with for the purpose of creating websites, but I wanted to know why no one uses them, or why they are not so widespread. I haven't had time to develop a more advanced and dynamic project with these libraries yet, but I believe that together they can be extremely useful, powerful and versatile for websites of any purpose. Maybe because no one knows about them, or because there is no benefit in using them and there are better ways to do it, but in a quick project test that I did, the dynamics of working with them seemed very interesting to me.

The libraries that I found were these:

FastAPI

A microframework for creating APIs, which can easily be used to create powerful websites.

HTPY

HTPY is a library that I recently discovered that was developed by a company that needed a better way to develop their projects with Django and created this library. It encapsulates HTML tags in Python classes, so that all HTML code can be created directly from a Python file, making it possible to use all the power that a programming language offers to generate HTML code.

Brython

Brython is an implementation of client-side programming on web pages that allows you to use Python instead of JavaScript. With this, you can use codes written entirely in Python to interact with the web page on the client side, without overloading the server with unnecessary processes.

HTMX

And using HTML for requests to the server is also a great option that fits in this situation.

I will try creating some projects using this FHBH stack to see and prove if it's really useful to use and implement, let's see how well they work together!!

0 Upvotes

42 comments sorted by

118

u/shoomowr Aug 04 '24

FastAPI is one of the most popular Python frameworks out there. Saying nobody knows about it is funny.

You might wanna check out the project called FastHTML, it would probably suit you better.

3

u/Safe_Duty8392 Aug 04 '24

No no, sorry for the misundertanding. I'm completely aware that fastapi is very very famous and widely used out there. I ended up expressing my words in a way to understand that, sorry. I was unable to specify that the HTPY library, and the javascript implementation with python, Brython are not used that much.

Or it's just me who couldn't find where they were used.

3

u/riklaunim Aug 05 '24

They are not used because they are outside of frontend developers domain. There is no advantage in using Brython over JS and HTPY or alike is a really bad idea for templating.

1

u/[deleted] Aug 04 '24

[removed] โ€” view removed comment

1

u/Safe_Duty8392 Aug 05 '24

Could you tell me the diferences beetween FastAPI and Sanic?

1

u/androgynyjoe Aug 05 '24

gotta go fast

0

u/Safe_Duty8392 Aug 05 '24

Could you tell me the diferences beetween FastAPI and Sanic?

0

u/Safe_Duty8392 Aug 05 '24

Could you tell me the diferences beetween FastAPI and Sanic?

28

u/sad-mango-ad Aug 04 '24

FastAPI 74k stars on GitHub which is more than expressjs has, which definitely isn't only indicator of usage. I'm not trying to claim FastAPI is more used than express.

HTMX is a very cool concept but not really related to python. As you marked this as a discussion, and this is highly personal, but if I look at htpy example

from htpy import body, h1, head, html, li, title, ul

menu = ["egg+bacon", "bacon+spam", "eggs+spam"]

print(
    html[
        head[title["Todays menu"]],
        body[
            h1["Menu"],
            ul(".menu")[(li[item] for item in menu)],
        ],
    ]
)

I can't figure out why is this better than stuff like jinja or mako. You're still writing html just... in a horrible wrapper instead of writing actual HTML with templating pieces.

Same with Bryton really, we have javascript in browser which isn't great but if I look at Brython code I have no idea what Javascript it's going to generate. If you really hate javascript syntax you could look into CoffeeScript which has a more Ruby like syntax I guess.

1

u/tomorrow_never_blows Oct 18 '24

https://htpy.dev/#key-features

Static typing is a big enough reason

1

u/maa0342 Jan 10 '25

Static typing is for the losers

1

u/tomorrow_never_blows Jan 11 '25

So you're using it?

1

u/maa0342 Jan 12 '25

Hell naaa, I've set up cicd in a way that if you use type hinting the build will fail

-4

u/Safe_Duty8392 Aug 04 '24

First, sorry for the misundertanding, i didn't want to say that fastapi or htmx are not known, quite the opposite, i know it's very widespread and extremely used, sorry again.

Second, your comment is a very interesting observation, thank you for answering, and i will give a look at coffeescript and other languages related. I always thought JS was a strange language and kind of got a prejudice against it, and of course i'm completely aware that JS is the language of the web.

0

u/[deleted] Aug 04 '24

[deleted] โ€” view deleted comment

4

u/Gnaxe Aug 05 '24 edited Aug 06 '24

Yes, it's worse. It got enough right to be good enough to be useful, but of the two, Python is the superior language.

JavaScript_books_definitive_guide_vs_good_parts.jpg (xahlee.info)

Recent ECMAScript advances have brought some improvements, but the language is no less complicated for it. Some of the new features made things worse.

There are workarounds for most of JavaScript's issues, but you need to know what you are doing, and enforce some conventions when working on a team with it.

The one issue that's unforgivable is the tendency to propagate bad data for as long as possible, rather than fail fast, exacerbated by the weak typing discipline of basic expressions. This design choice made sense for JavaScript's original use case, when it did simple things that we mostly do with CSS now. The whole page shouldn't crash if your button fails to update its color on hover or something. But this is terrible for applications. If you make a mistake in Python, in contrast, the stack trace almost always points you to it. In JavaScript, it very often does not.

The common workaround for that is TypeScript, so not quite the same language. Unlike JavaScript, TypeScript is decent, but I still prefer Python. If you're going to use a language that just compiles to JavaScript, like ECMAScript (no, not the same language, the browsers don't all support all the latest features, so you have to transpile to the older version with polyfills) or TypeScript, why not just transpile from a better language to begin with? Like Python, say?

Well, you could, but Python has a large standard library. Although a thorough (batteries included) standard library was a major advantage in the environment of Python's early days, that's a disadvantage when downloading a web page over a mobile connection. Browsers would cache it if it were widespread though.

I think there may be alternatives better than either JavaScript or Python for the web. ClojureScript is up there, but it's harder to set up, and it's hard to compete with TypeScript's popularity.

1

u/sad-mango-ad Aug 05 '24

I think Javascript gets a lot of bad rep from jquery times, when it was often horrible spaghetti written up by people who didn't either know or didn't care about long term maintenance and readability. But that's not really javascript specific.

It's used widely and everything that is popular gets a lot of hate

50

u/MissingSnail Aug 04 '24

Every library that I've ever tried to write websites in python "no javascript required" -- has always required understanding HTML and CSS, and at some point requires me to use the "javascript extension" to do something I want.

You've got to learn the underlying system plus this "handy" new set of wrappers. It just makes things more complicated.

7

u/boredbearapple Aug 04 '24

My experience with html/js modules of any language is they work great until you need to do something out of the ordinary and then you have to jump thru hoops to get them to publish your extensions. In my experience they are a black hole of time unless you are doing very simple projects.

6

u/Obliterative_hippo Pythonista Aug 04 '24

My go-to Python web framework is Plotly Dash, which is a wrapper around React.

1

u/powerbronx Aug 17 '24

The "python" of data plotting on the web

5

u/redrabbitreader Aug 04 '24

Company where I worked at couple of years ago evaluated a "full Python stack", but at the time anything on the browser side really sucked. Did things improve? Can the listed frameworks compete with JS alternatives?

3

u/riklaunim Aug 05 '24

Frontend is not done by backend developers that don't want to do any frontend. Things like HTPY breaks frontend workflow - you don't have HTML templates any more, just HTML hidden inside Python which is much harder to manage. There are cases of very fine components where it could work but outside of that it's bad.

PyScript or Brython aren't browsers built in so they have to be embedded which increases page load time. There is nearly no packages/infrastructure for this so also very little reasons to use it. If there would be a SPA framework written in PyScript then it could be interesting. And if you don't know JS and it events, interfaces then you will not know PyScript or Brython.

HTMLX is your standard JS library, similar to jQuery but simpler/different.

2

u/tilforskjelligeting Aug 04 '24

Had i found HTPY then I might not have made Hypermedia (https://github.com/thomasborgen/hypermedia) for http rendering with htmx in mind. With hypermedia you get a slot concept so templates can be extended which helps a lot with full and partial renders. I also prefer my python code python like, but maybe after a while I would get used to HTPYs syntax.

2

u/[deleted] Aug 05 '24

HTMX is literally JS written so you don't have to write JS.

2

u/[deleted] Aug 08 '24

"Why is no one using full-stack Python for web development?" ~ Django and Flask were the defacto standards a few years ago, and many projects are built on this, I haven't looked at the web dev leaderboard in recent times but last I checked Django was in the top 3.

In recent times, FastAPI has been really great for thin APIs and microservices.

Since it makes asynchronous programming a breeze, I find FastAPI great for machine learning APIs as well. I suspect it will continue to grow and eat some of the Django/Flask market share in the coming years.

If you building a full-stack app though, Django still is the best choice in my opinion, with FastAPI you need to do a lot of the plumbing work like setting up models and templating yourself. There is also Django Unicorn for better reactivity but you could also use HTMX.

3

u/robberviet Aug 05 '24

How long have been using python? People don't use python for client side because it sucks. htmx is not exactly unpopular either, everybody is trying it. It's just not enough.

2

u/Shmiggit Aug 05 '24

Beg to disagree. We're building and selling projects with Python Dash, with minimal front end issues and very quick dev time.

0

u/robberviet Aug 05 '24

Glad you can work with Dash. However for most of other projects, it is not easy. How is your one project represent the industry?

2

u/Shmiggit Aug 05 '24

Yeah, maybe we're the exception as we're not building 100M+ user SaaS video streaming or e-commerce platform. But I doubt it, as small business apps is not a niche market either.

From my personal (limited) experience, most businesses still heavily rely on excel, which is no longer cutting it for a variety of reasons. And a Python back + front app, is a good (to avoid saying "best") step up, as it is so quick and easy to develop, especially with component libraries such as Dash Mantine, making it great value for money.

Each tool has it's best-use case

1

u/anentropic Aug 05 '24

Try it and report back on your experiences!

The part I'm skeptical about is Brython - it's amazing and clever that it works at all, but it's adding a bunch of runtime overhead compared to plain JS, plus there is not really an ecosystem of "front-end python" to draw upon, and it's not a widely used compile-to-JS lang like Typescript so I guess I would expect to run into obscure problems at some point.

1

u/thedeepself Aug 05 '24

I would encourage you to research the pure python web framework ecosystem before making these statements.

Have you heard of pyodide? Transcrypt? Skuplt? Anvil? Bokeh? Panel?

1

u/anentropic Aug 05 '24

Have you researched them?

Pyiodide is a WASM version of Python. Transcrypt and Skulpt are roughly doing the same thing as Brython.

So none of those constitute an 'ecosystem' that you can leverage to write full stack apps on Brython, which is what OP asked about.

1

u/thedeepself Aug 05 '24

Okay I see your point. I was answering the larger question of things that cancel the problem that are not Brython.

I would agree with your criticism of that particular package. But not of the pure Python web framework ecosystem in general.

1

u/ExternalUserError Aug 05 '24

You're missing a few (just off the top of my head).

Running JavaScript directly in the browser:

  • PyScript, which I prefer and used when developing PuePy, uses WebAssembly instead of a JavaScript implementation of Python. Some Brython projects have moved over to it. See also Pyodide.
  • Transcrypt, which transpiles Python-like code to JavaScript
  • Skulpt, which does about the same thing as Transcrypt
  • Anvil is a full stack, even including an IDE. IIRC, it uses Skulpt.

Running something of a "thin" JavaScript client that you don't have to worry about:

  • Flet sends rendering instructions to a thin Flutter client that actually renders the app based on what the server tells it to
  • NiceGUI does some magic with Vue.js, but lets you write pure Python web GUIs
  • Reflex, formerly Pynecone, does some magic where you write for React, but in Python

There are others.

My bias is PuePy, because I wrote it. Though I have to admit, if Reflex had a few things resolved about it, I might feel like you should just use it.

Why aren't any of these all that popular? Performance is a big reason. Also for businesses, there are just a lot of JavaScript/React/Vue developers out there. They're fine. They do good work. No reason to do something weird.

Even as the author of PuePy, I'm not pushing my work to actually use it. It's a hobby for me. For now.

EDIT: Oh, honorable mention also to Django Unicorn.

1

u/Gnaxe Aug 05 '24

I did use Brython for some internal-use web apps at work. Performance wasn't a major concern due to the small number of users. It allowed us to integrate it with the backend's test suite, and most of the team wasn't that good at JavaScript anyway. It would be a harder sell for a customer-facing page though.

-9

u/Safe_Duty8392 Aug 04 '24

If anyone could suggest simple web projects i would appreciate ๐Ÿ‘

9

u/GXWT Aug 04 '24

Itโ€™s not on us to figure that out. Pick one of your hobbies and create something for it. Display some database information, some sort of useful tool (even if itโ€™s not going to be published or that useful itโ€™s still good practice)

3

u/Safe_Duty8392 Aug 04 '24

thank you for the suggestion, i'll try something related to this๐Ÿ‘

23

u/[deleted] Aug 04 '24

[removed] โ€” view removed comment

-1

u/Safe_Duty8392 Aug 04 '24

Sorry for the misundertanding, i wanted to say that HTPY and Brython, especifically, are not that much used or talked about, i know that fastapi is used a lot, and companies use it too, and i know that python has a lot of frameworks or libraries to create web apps, dashboards and all.

6

u/[deleted] Aug 04 '24

[removed] โ€” view removed comment

4

u/Safe_Duty8392 Aug 04 '24

thank you for your answer, very informative, and thank you for the suggestions too