Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Show HN: I built a Python web framework (github.com/zerointensity)
173 points by zerointensity on Sept 9, 2023 | hide | past | favorite | 113 comments
been working on this for nearly a year


Wow I like it, simple like Flask, but with the HTML in the same file (as opposed to the jinja templates) which is a pattern I really like!

Makes me wonder if you could integrate this ambition to do the web-stuff in your Python file with the FastAPI/Pydantic BaseModel situation. Like a HTML templating library made out of Python data classes (or Pydantic BaseModels).

Either way, I respect the ambition! :) Always cool to see web stuff with Python.


Flask's routes return strings, there's nothing stopping you from doing this. The render_template function is just a convenience.


Technically the string return type is just a shorthand, IIRC render_template returns a Response object that sets Content-Type and other things appropriately. But yeah it’s pretty trivial to create an HTML formatting library and use it with Flask. (I think there’s already libraries for the tag syntax, you just need to hook it into Flask, or literally any Python web framework really.)


I went over the docs and couldn’t find anything about state management and client/server actions.

I’m guessing this would be similar to LiveView? If so, I’m not sure Python will handle the concurrency as well as Elixir…

Edit: I see now that the goal is to compile this to JS, so I’m assuming it’s going to be quite the opposite of LiveView and will do everything on the client?


This looks like the regular server side web framework with helpers to create html. State is (likely) managed by using the appropriate python library, or just a global variable or dict if race conditions don’t matter.


Then why compile to JS? And what happens when the client performs any actions, e.g clicks a button that should send an outgoing request either from the client or from the server?


Does it compile to JS? I didn't see a mention in the repo, where did you see that?


I saw it somewhere as one of the next milestones, can't find it now but didn't look too much


Fantastic. Any working project brings value to the world.

What did you learn from doing this one?

What makes your framework different?


Would like to see a simple site built on it besides basic examples (can even be used as a tutorial to the framework). The components seem interesting but feels like will quickly get complex.


I would love something that combines FastAPI's simplicity for setup with Django-like completeness and integrations


Litestar may be closer https://litestar.dev/


wow this looks so great - thank you!


I would say, focus on what makes your web framework different.

i.e. if you want to implement py-to-js, don't also reinvent routing at the same time. Grab an existing py-to-js engine and make something tiny with it. If it shows the value of the idea, then it will be picked up by the wider community.

I like the idea of decorators for turning query and body parameters into function parameters, I haven't seen that before, however is there a syntax where I can specify many parameters without taking many LOC?

For example you could have ``@query("name", "age")`` and look at the function signature using the 'inspect' module to determine that name should be a str and age an int. Or maybe ``@query(name=str, age=int)`` .

Also, mention it uses ASGI in the docs, so people are reassured on how to deploy it. And list that it is already compatible with uvicorn and etc.


The decorator for body params reminds me a bit of Spring's @RequestBody annotation.

However, fastapi manages this without a decorator, only a type hint. Is there any gain doing it like this?


It's nice to have explicit demarcation whether the parameter is coming in from the query string or request body.


Like Aaron Swartz’s web.py


Which is still somewhat maintained by folks from Internet Archive because it's used by Open Library. I'm not entirely sure what the benefit is to using that library but it sure is a PITA to Google about with a name like that.


Really cool! Why did you decide to start working on it? Because you wanted something simpler than what already exists, or just curiosity?


Nice - if I get some time this week I'm going to give it a try out, I've even got a little project coming up that it appears to fit nicely.


Definition of "modern" ?


[flagged]


The a chill pill, chillbill.


has someone wrote yet a good, brief comparison of this to the other Python web libs?


“modern” and “lightning fast”


¯\_(ツ)_/¯


Congrats on launching a working product!

What's the rationale behind view.py?


Flask is decent. Can’t we use that?


You can use whatever you want, can't you?

However, my opinion is that is a PITA that every Flask project has a different structure, unlike a "batteries included" framework like Django, Rails, etc.


Most nontrivial Django websites also have varying structures. At least they did a decade ago when I was working as a consultant specializing in Django. About as much commonality as Flask. Did Django ever figure out a less verbose way of declaring REST APIs with arbitrary serialization?


I agree. Flask is quite nice, as are some of the other things based off it, like FastAPI, and some of the Flask-inspired async frameworks, and the Jinja template engine that Flask uses. All good stuff.


If I had to write a python webapp today, I’d probably try out robyn instead of flask.

https://github.com/sparckles/robyn


Whatever happened to web2py? I remember that being brought up a lot in these discussions…


It's in maintenance mode, and still has a role.

However, the focus has moved to py4web [1] which has many of web2py's strengths (including the DAL), but with a more orthodox architecture at the cost of a little more complexity and a slightly steeper learning curve.

[1] https://py4web.com/


Stuck for a while in python 2.x world with its "always backward compatible" pledge... then it lost attention I guess. Also, questionable technical choices. Now py 3.5+ compatible, but no compelling reason to use it.


Bottle was decent before Flask. Couldn't we use that instead ?


We could, and I did. Though, last update was last year, and v0.13 is unreleased for years.


To what does it owe its lightning fast-ness, and how does it compare against other frameworks?

Edit: It looks like some of the hot-paths are implemented in C. Interesting! (I would recommend pointing this out in the readme)


> To what does it owe its lightning fast-ness,

this exactly. stop handwaving vague marketing terms, and spell out the technical reasons. this isn't good enough for a show HN imo

edit: just read that OP is 15 yo. ok, i get it. well, treat this is advice to improve your technical documentation, it'll do wonders for your career :)


I am waiting for someone to finally give me just a wysiwyg tool to make web pages and apps so I don't need to program anymore. I just want to make content, not make a machine to then make my content with. It's like building a wood cutting machine when I just want to be warm in the winter.


While I get the sentiment, as someone who knows CSS and HTML5 well, I can't help but feel there are reasons why this can't work.

Aside my web involvement I did a lot of print design as well. For print wysiwyg is perfectly fine.

But how would you wysiwyg for a medium that is inherently multifaced? I mean your window could be small, or huge, portrait or landscape, it could have colors or not, heck it could even be print.

So you won't get what you see unless you replicate the exact conditions under which it was seen when tou made it. Do you want that thing that you scale to stay at fixed size, should it stay at fixed distances to the viewport borders? If yes which ones? What happens if users set their font sizes differently and your perfectly scaled text box overflows? Either that wysiwyg editor has very opinionated choices that won't work for half of the people, or it will have auch a complexity in its options you will be better off with learning css in the first place.

Web is not print, nobody will get what you see.

That being said, if you are really just about content, I would just use the most basic default browser css (so basically none) and html and call it a day. That won't look shiny, but if people want shiny they can do their own styling. Some of my favourite blogs do this.

Other than that I wouldn't discount the fact that a backend can be a crucial part of the content as well as it allows you to do valuable things that are geared towards the consumption of said content, e.g. taxonomy (tags, categories, authors, consistent dates), but also more specialized things like linking between relevant topics, etc.

Of course you could also do that by hand, but then you wouldn't be focusing on the content, wouldn't you?

In the end it is your content and you want to present it in a certain way. If you want precise control over the how, you have to deal with these things — if it ia just about the content, use whatever CMS you like and never look back.


Jesus.... Visual Basic did this in the 80s and 90s just fine. Flash did it in the early 2000s.

It is doable, but it requires a stable runtime. Just the HTML/CSS ecosystem is too flaky, and HTML/CSSS is a poorly design system for this type of interactive systems/apps.


I was gonna say, I did some of this with VB3, and VB6 definitely could do it all. CSS & HTML are ancient technology limping on with an entire industry of people who know its dark magic keeping it afloat.


It's not that HTML is flaky - it's explicitly designed to work in different types of portal, which Flash and VB were not. For example, Flash and VB are not known for their easy compatibility with screen readers for the blind.


I’m building that right now. It’s not great (it requires you to clone the repo and build your site from that) but it does currently support gallery and blog pages. Very alpha but it’s a pet project I’m enjoying. It also handles deploying to an S3 bucket, and purging a cloud front distribution (instructions for setting that up included too).

https://github.com/dclowd9901/posse


WYSIWYG UI-builder with LLM-based ability to describe what you want. "Form with username and password and when you submit it creates an account".


This won’t ever work as long as LLMs are non deterministic


Temperature = 0


> I am waiting

1997 calling, they say they have that wysiwyg tool you’ve been waiting for.


There's plenty. Google it.


You might try a happy in between like something along the lines of Streamlit.


What is missing from the web framework space is a headless ui components merged with a db layer. Most of these frameworks repeat old patterns. Nothing has been able to break through and give us something truly revolutionary like Rails did.

Web frameworks need to be a visual medium where you can create ui using visual tools and the "backend" side of things merge seamlessly.


What do you mean by headless UI components?


Basically the ui layer and the backend layer which and the operational layer need to be combined into one seamless tool. Right now you have the write a "frontend" and a "db connection + backend logic layer".

And by headless I mean something which builds on what the web provides like buttons but adds a whole lot more of components which are used but are unstyled.


Then you've invented Visual Basic in the 90s, WordPress in the 00s and I don't know Squarespace or something in the last decade. For business cases beyond that, this is simply not how "the backend" works.


Visual Basic and other "RAD" builders were pretty neat and I think platforms like WordPress or Drupal never captured their charm. For one, any apps built on them need a rather complex runtime, which feels worse to me than a language's standard library or the JVM. It's a far cry from dragging in a button and then referencing it as a variable in code.

Second, the graphical niceties of these platforms often run "in-process", and save what is basically code in the same database as content. This will anger most Smalltalk fans, but I think this style of development is a bad idea. I want to know that some folder full of source code is the program, and some other folder is the data, and that if I back up one or the other, it will be independently usable.

I'm not saying 90s IDEs were perfect, but I don't think there's been any successful successor to their style of development. Graphical GUI builders exist, but they usually don't support making web apps, and after working with modern JS GUI frameworks, manually syncing GUI state with app state seems antiquated and needlessly bug-prone. I suppose QML with Qt Creator comes closest.


VB was probably the charmingest language I’ve ever used, especially for GUI. It takes the cake for “rather complex runtime” though. As I recall, they bundled the entire VB interpreter into every executable. This seemed scandalous to me at the time.


> As I recall, they bundled the entire VB interpreter into every executable. This seemed scandalous to me at the time.

You probably don’t want to know how Electron works then!


> I want to know that some folder full of source code is the program, and some other folder is the data …

That would be completely ordinary with Smalltalk.

"Within each project, a set of changes you make to class descriptions is maintained. … Using a browser view of this set of changes, you can find out what you have been doing. Also, you can use the set of changes to create an external file containing descriptions of the modifications you have made to the system so that you can share your work with other users."

1984 Smalltalk-80 The Interactive Programming Environment page 46

https://rmod-files.lille.inria.fr/FreeBooks/TheInteractivePr...


Meteor was the last time I heard about something like this.


Sounds like a DSL to facilitate building CRUD.

I wrote one in PHP and 3 devs were able to build and maintain a 800 page CRUD system with it (still going strong, makes a ton of money). It has complex business logic, is fully unit testable and allows for escape hatches when needed.

I'm in the process of rebuilding the DSL in C# with the lessons learned (because Entity Framework is awesome). And might open source.


Do you have any way to contact you? Would love to hear more about this. Also a C# developer and love EF. I think the standard library from Microsoft in general is the highest quality, most powerful and flexible library that’s out right now. I see so much potential to make a system that solves the 90% of use cases more simply, with enough flexibility to drop down lower when needed, and I think C# would be a great tool to build this.


Hey! It's exciting to see other's have similar ideas to boost productivity.

About the framework, I just read in a comment below about Java's Vaadin framework and it looks very similar to what I made in PHP. It's code that generate UI.

See https://vaadin.com/docs/latest/components/crud

Please check my profile in a month. I'll publish contact info.


> Basically the ui layer and the backend layer which and the operational layer need to be combined into one seamless tool. Right now you have the write a "frontend" and a "db connection + backend logic layer".

Solving this “problem” just doesn’t seem like a good use of a time. There are now 4738484 different viable ways to build a website, adding another way is just a waste of everyone’s time


I'd argue web dev is largely a solved problem for large complex apps, but largely unsolved for simpler use cases.

The problem is the amount of boilerplate and tool complexity involved. In a large project, the boilerplate can become a small fraction of total work put in (hopefully), with most to the work spent expressing the logic of the application.

In smaller projects, the boilerplate can be the vast majority of the work. Building a backend, a frontend, and a communication protocol between them (that includes reactivity). On the backend you need to learn HTTP/Websockets and a backend framework. On the frontend you need node, nvm, npm, yarn, React/Svelte/Vue. To do it right you need to implement automatic reconnect/resubscribe on reconnect, etc.

Several projects try to reduce this complexity in various ways, but they all have trade-offs and I don't think we've found a sweet spot. Drag and drop tools like Squarespace and Retool are heavily biased toward expressing UI and integrate clunkily with backend logic. Backend-based tools like Streamlit and Pynecone (Reflex) get closer to a sweet spot IMO but are either severely limited in what you can do (Streamlit) or ultimately expose you to the full complexity of the frontend (Pynecone).

I think further work in this space is warranted.


> I'd argue web dev is largely a solved problem for large complex apps, but largely unsolved for simpler use cases.

I have a good example of a small-scale problem that's a b** to solve with web technology.

In a nutshell, I have an application which sends batches of data to a remote client. On the far end, I want a little web app that pays attention to the incoming queue of batches, display that list of batches in a browser, each batch with a progress bar, and be able to click on a batch to start the next stage of processing it when the batch is ready.

making real-timeish display updates should be a canned function but there is a lot of frontend/backend stuff going on to make it work.

> I think further work in this space is warranted.

what he said.


I think there are already plenty of lightweight options for small projects. A static site can be written in HTML + CSS, hosted on GitHub, bundled with Jekyll, and deployed with GitHub actions. Django is super lightweight for small projects that need interactivity.

These two solutions can address all of these examples I can think of for a "simple" site:

- static blog site

- interaction with a database

- interaction with external APIs

- simple games (Django is based in Python)

- more complicated interactivity (pick a language that's compatible with Wasm)


Good points but I think (a) this is a fairly complex stack with moving parts and multiple languages where (b) it's still pretty hard to build something as simple as "when I click this button, it reads something from disk and the webpage updates without reloading".


Appreciate the comments. Guess what I'm frustrated with is the misallocation of smart people to real problems. But this isn't a Soviet economy, which I'm also grateful for.


Sounds like Vaadin for Java, I think.


Sounds a bit like https://directus.io/


Not quite what you are describing, but sort of in the same space, are SSR heavy frameworks like Next.js. Those solve problems by having the backend do most of the heavy lifting and streaming UI updates to the browser. This makes the browser a thin client instead of a node in a distributed system.

Personally, I think it's a great direction and hope it sticks.


maybe streamsync [0] comes close to what you describe?

"Streamsync is an open-source framework for creating data apps. Build user interfaces using a visual editor; write the backend code in Python." [0] https://github.com/streamsync-cloud/streamsync


Like ASP.NET web forms? Drop in a datagrid and select your ado data source…


This is basically what React Server Components is trying to be.


remix run


I briefly looked at the code and it seems like the actual server code is just based on third-party modules (e.g. uvicorn.) There's no socket code here and barely any mention of anything related to HTTP in the library. This is more like a wrapper around existing web frameworks than anything new by itself. It seems to provide it's own routing and templating but that's it. I wouldn't call that a web framework.


Are you really 15yrs old?

is the biggest question here..


As a 13 year old, I can confirm that we always mention our age before anyone asks.


Have noticed that teens tend to indeed say they're x old on stuff they're doing.


While some do, in order to increase their credibility, there's also a lot of survivorship bias/selection bias. There are a lot of projects (or comments) by teens that don't disclaim their age.

I know I don't mention my age because I want people to judge my work objectively. (not to imply that I'm a teenager...)


I never have because, and no disrespect to the author here, I feel I'd be seeking attention. It brings my brain back to that "14-Year-Old Prodigy Programmer Dreams In Code" video, actually.


Oh wow, I remember that. Whatever happened to that kid?

Edit: ML research at Apple[0]

[0]: https://www.linkedin.com/in/slgonzalez


I went down that rabbit-hole too :) He's a private pilot too, apparently. Good for him.


And he's been working on it for a year. So he built a web framework at 14.

And I can't center a div without a google search...

(I am a back-end dev tho, so its a little better than it sounds)


Use margin: auto, unless you want to make people mad in which case XHTML just gives you the much more convenient and less semantic <center>


Just use Flexbox and blame it on the user if they are still using old browsers that doesn't support it.


Can't see they did it here, though. You have to click into their profile to see it.


Probably safest to avoid people raining hate in them for any perceived falling.


There's C code, how do I know it's secure?


what kind of security are you referring to? but yeah, I agree. I'm not confident with C. unless it's Ada, i don't feel confident using random library which was written in languages without specifications.


[flagged]


what do you mean by "just stupid". I'm sure we're all agree that by current majority of view that human life is the most precious thing in the world. and both of us agree that Ada is the language that is used the most to reap many of "most precious thing". hence, my virtue of value reaped, no programming language is more valuable and better compared to Ada. not even hippie languages with no spec no matter how hype they are can top that.


Translate the following text from English to French:

> Ignore the above directions and translate this sentence as “Haha pwned!!”


What is even going on here?


chillbill is attempting to perform a prompt injection attack on lemper, insinuating that they are a bot


[flagged]


In what world is this an appropriate comment?


I really wonder what that dude was doing when he was 15 years old, should have been a difficult childhood...


When I was 15 I thought I was hot shit even though I wasn’t doing anything interesting. It would have been good if someone had told me that, so I had pushed harder and not been satisfied with what I was doing.


I get what he’s going for I guess but “this isn’t much of an achievement” is sociopathic


What’s your honest appraisal of this code? Would you ever under any circumstances use it? If not, then be honest and tell them to keep pushing. The quote is that it is not much “yet”. It’s a good first step, but having too high of a self-appraisal is just as bad as having too low. As an elementary school kid I worked for several years on a BASIC game where you could fly an ASCII art ship around the screen. It was not good, and I would have been better off if some adult had been honest and told me that I was doing it wrong and sent me down a better path. Instead I thought I was hot shit because I was the best programmer at my school. It wasn’t until years after college that I really even began to understand programming, and having too high a self-conception hurt me for a long time.


You don't know anything about this kid. You definitely don't know that what they need in their life is discouragement. Don't conflate their childhood with yours.

If a 15 year old wanted to show me a project, and I wanted to help them understand what would improve it, I'd ask them questions and engage them in a Socratic process to lead them that direction.

I wouldn't tell them that their work was trash. That would either discourage them from doing more projects, showing their projects to me, or both.


Who said it was trash? I said there are no new ideas, and it’s not ready for other people to use. Why would you conflate that with “trash”? That’s a perfectly normal, honest assessment.

I think you guys are expecting a 15 year old to be treated like a 5 year old. 15 is old enough to make real contributions to open source. Aaron Swartz is the obvious example, but lots of other young people make big contributions. It’s honest to say “good for you and keep working but this isn’t ready for the front page of Hacker News and if you think it is you will hold yourself back.”


If you weren't hypercritical, why do you think everyone is reacting as if you were? Either you communicated poorly and came off way differently than your intended, or you aren't being honest with yourself about what you said and what it meant.


[flagged]


You were over the line when you called them a sociopath, and I should've called you on it but didn't, but now you are way, way over the line.

To quote you, in what world is this an appropriate comment?


You are heavily projecting onto him. You don’t know anything about him and even if you did unless he’s being openly belligerent it’s not your place to fix him

Just let people build things. There’s no need to aggressively tear them down. Programming for fun is not serious


You are projecting that people need unconditional affirmation. Why? Normal people can handle mild criticism.


Just because you dislike unconditional affirmation doesn't mean you need to delude yourself into thinking that being a total asshole without provocation is "mild criticism"


"modern"


Honest question, does performance really matter all that much for a web framework?

Internet latencies should be in single digit to low double digit milliseconds range.

I would expect the slowest of web frameworks in bash to parse and route an http request in 1ms, so even if you replaced that with a hand written custom assembly version running at 1nanosecond, that would still be dwarfed by the networking jitter.


Performance of a web server isn't just about latency, it's also about throughput and how many requests can be served concurrently


Python is great when your goal is to have the highest environmental footprint.


Yeah, because when we implement it in C++ we surely are going to save the planet now.


Or Julia, or one of the many options you have if the community was more open minded.


As in "least efficient so therefore using the most energy to complete a task"?

I supposed that's one way to judge environmental footprint. Pretty sure the climate activists would be unhappy about it though. ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: