Show HN: Pynecone – Web Apps in Pure Python

github.com

209 points by picklelo a year ago

Hello, we just launched the alpha release of Pynecone - a way to build full-stack web apps in pure Python. The framework is easy to get started with even without previous web dev experience and is completely open source / free to use.

We made Pynecone for Python devs who want to make web apps, but don’t want the overhead of having to learn or use Javascript. We wanted more flexibility than existing Python frameworks like Streamlit/Dash that don't allow the user to make real, customizable web apps.

With Pynecone, you can make anything from a small data science/python project to a full-scale, multi page web app. We have over 60+ built-in components and are adding more.

We are actively trying to grow this project so no matter you skill level we welcome contributions! Open up an issue if you find missing features/bugs or contribute to existing issue.

rahimnathwani a year ago

A comment at the bottom of the thread (at the time of writing) explains how it works:

  In Pynecone, the frontend compiles down to a NextJS/React app, and the backend is a FastAPI server. Events are sent as network calls that update the app state, and the state delta is sent back to the React app, which updates the UI.
EDIT: The gallery is also useful: https://pynecone.io/docs/gallery
  • stevesimmons a year ago

    Thanks for highlighting this comment.

    A succinct explanation of the underlying design is the best way to get me from "oh that's cute" to "wow, I want to try this".

  • dandigangi a year ago

    That's going to be rough to maintain as they update Next/React if this thing lasts for any reasonable period of time. No tests written at all either.

    • apetuskey a year ago

      This is just a question of how involved we can make our open source community and that it not true about the tests https://github.com/pynecone-io/pynecone/tree/main/tests we also a have GitHub action set up, every pr that runs these test. Today was literally our first public launch we will improve as time goes on

      • dandigangi a year ago

        Apologies - posted before I went through everything.

        • apetuskey a year ago

          No problem thanks for checking us out!

  • zackees a year ago
    • folkrav a year ago

      Any source for this? FastAPI advertises itself as production ready:

      > Robust: Get production-ready code. With automatic interactive documentation. [1]

      > FastAPI framework, high performance, easy to learn, fast to code, ready for production. [2]

      [1] https://fastapi.tiangolo.com/ [2] https://twitter.com/FastAPI

      • bgm1975 a year ago

        I’m assuming the parent is referring to Pinecone, not FastAPI.

theptip a year ago

It's worth noting you can do something similar with Django & HTMX. These two combine to provide a DX in the same rough direction as Rails Hotwire and Phoenix LiveView (although the low-level semantics are different; it seems Pynecone is more similar to LiveView if I'm following correctly).

While I've not worked with it, one example of Djangonic Components might be Wagtail's: https://docs.wagtail.org/en/latest/extending/template_compon...

Interested in others' thoughts on what Pynecone will do better.

  • kortex a year ago

    Looks like Pynecone uses Fastapi under the hood, which is a huge win for me. I can't stand "the Django way" of doing things and find Fastapi's philosophy much more harmonious with the way I think. So if you are the kind of person that enjoys a more functional style, with dependency injection, static types, etc, this is nice. If you like dynamic everything, this is probably less appealing.

    • bb88 a year ago

      We get huge development optimizations by using django over other python frameworks.

      I think a better approach would be to make the back end pluggable to put whatever backend framework you want. And then you don't have tell people "well you can't use this fancy new tool, unless you move your entire stack over to fastapi..."

      I mean there doesn't seem to be any reason you can't have a PineConeView that subclasses the django View class...

    • theptip a year ago

      I do like FastAPI. django-ninja looks interesting as a potential alternative in the functional & Pydantic-typed API style, while still keeping the benefits of the Django ecosystem and ORM.

  • do_anh_tu a year ago

    This is my stack when I want to ship MVP fast. Django + HTMX help me at least 10x more productive.

xcdzvyn a year ago

> width="100%",

> height="100vh",

> bg="radial-gradient(circle at 22% 11%,rgba(62, 180, 137,.20),hsla(0,0%,100%,0) 19%)",

Smells like leaky abstractions. Surely it's possible to abstract this into a strongly typed API?

Edit: https://pynecone.io/ looks a little screwed up for me on FF 107: https://i.imgur.com/ICu29UL.png

  • picklelo a year ago

    Our components can be styled using any valid CSS which is what you see here. We do have plans in the future to make a more Pythonic API for styling :)

    Thanks for pointing out the UI bug, we'll work on a fix!

doteka a year ago

It seems once a year somebody writes a library to do this. It never takes off, because the main difficulty in developing web applications is not “learning JavaScript“.

I have 3 questions for the team. Who is the target audience exactly? How is this different from Anvil, Toga, Streamlit or the previous 36 attempts? And if learning JavaScript is too difficult, what exactly makes shoving the DOM API into another language easier? You still need to learn all the same things but now there’s about 9 orders of magnitude less working examples to copy from.

  • apetuskey a year ago

    You make a couple points here what do you mean "it never takes off" Streamlit was a very successful project in terms of number of users and is still growing today. I talk about how we are different in some of the comments of this post aswell.

    • austinpena a year ago

      Yeah Streamlit is incredible. I don’t think it’s trying to be a Web app framework. It’s such an easy way for me to deploy my data visualization.

    • askvictor a year ago

      Anvil still seems to be kicking along too...

  • upbeat_general a year ago

    As someone who used to do webdev and now works in Python, I've been wanting something like this for a while.

    The barrier of writing both a front and backend for a simple demo/viz tool is pretty high (relative to the time it takes).

makestuff a year ago

Seems really cool for putting a frontend on a data science app. All of my data processing code is in python already, but this would be really cool to add a dashboard or other features without needing a separate tech stack.

  • picklelo a year ago

    Yes this is a great use case we're targeting. I've used Streamlit in the past and it's easy to get started with, but I found limitations in terms of components, styling, and performance. Since we compile down to a NextJS app, we aim to have the flexibility of traditional webdev with the ergonomics of Python.

    • d4rkp4ttern a year ago

      Indeed, I’ve tried streamlit early on but it was very limited in layouts and I had to do all kinds of gymnastics to deal with state.

      Gradio seems more popular for building ML driven demos though I have not used it. (I actually am curious why it’s more popular than SL).

      Anvil is another “python web app” project I poked at briefly but didn’t get far

appveyor a year ago

Congrats on the launch! Great project and nice execution!

Very similar to what we do on Flet: https://flet.dev The major difference is that Flet uses Flutter to build UI and can target desktop, web and mobile. Also, we use WebSockets for communicating with the server which gives lower latency (the delay between a click on a button here https://pynecone.io/docs/getting-started/introduction and UI update could be annoying).

  • apetuskey a year ago

    Thanks yeah we really like your project as well. We chose the react/nextjs ecosystem because we found it to be more developed and widely use than flutter. Which gives us benefits to be able to wrap more libraries either in our pynecone framework or make a third party component library.

    We thought about adding web socket and are still debating. The latency here is not from our framework though its from our server getting slammed with hacker news and reddit from our launch lol. We found the overhead of sockets not worth to for the majority of our apps.

    • dospunk a year ago

      > The latency here is not from our framework though its from our server getting slammed with hacker news and reddit from our launch lol.

      Seems like this could be a major barrier to scaling, especially if /all/ reactive state has to be handled through the server. Maybe a future feature could be a WebState class that provides reactivity only on the front end?

  • ofrzeta a year ago

    It took me a while to re-find a "Python web app" project that has been posted here and that I vaguely remembered. So I am gonna post it here. It's Pglet https://github.com/pglet/pglet and Flet seems to be its spiritual successor.

  • sukh a year ago

    First time reading about Flet. Good technical guide, a few typos but pleasure to read. Hope to try the project. Thanks for sharing.

  • digitalsankhara a year ago

    Flet is a new one on me. Thanks for the link, I'll give it a try.

vishnudeva a year ago

Been a lurker on Hacker News for years but I created an account just so I could say how excited I am for this! Love the effort you're putting into it. Streamlit was awesome but felt really painful to use whenever you want to do anything slightly out of the main path.

I eagerly look forward to the day this becomes stable. Looks like a project that will stick around for a long time, especially with the care being put into it.

Good luck team!

  • apetuskey a year ago

    Wow thank you so much we really appreciate your support! We have worked really hard on this so its great to hear there are people who value it.

    We will continue to improve the framework if there are any bugs/confusing you have in the mean time feel free to submit an issue/discussion.

  • picklelo a year ago

    Thanks so much for your kind words! We think our approach can really simplify web development and make it accessible to a larger community. Excited to see what you build with it!

bigpeopleareold a year ago

I don't want to knock on this accomplishment at all and I am well aware that these tools have its use-cases. However, I am just talking anecdotally and with experience with other things.

I think Google Web Toolkit started the idea of compiling X-to-Javascript. I am not sure, but it was the first I seen. I used GWT a long time ago and know it has improved a bit, but I always have sneaking feeling that the language-as-abstraction over JS feels excessive and extra work to maintain. I mean, I want to like this, but I can never justify using these toolkits. I think for something like PyQt, it really makes sense to have a language wrapper. Many people do not necessarily work in C++ or Qt's flavour of C++. But, if you are going to do anything in web dev, just learn JS/HTML/CSS. If you know that stack, these tools are really not that useful. The stack is probably the most well-documented application development space known to man now :)

However, I am always wanting to learn what people actually do and why they make tools like this. I just would never reach for this type of tool personally.

  • jennasys a year ago

    I used GWT a long time ago and it was great for being able to write a complex algorithm that had to run on the server as well as in the browser. It saved a lot of time and trouble, and you always knew that the version running on the server was the same as the one running in the browser.

    If you are already adept at coding in JavaScript and you actually enjoy using JS, then you would not be the audience for these Python (or other language) web dev projects. However, if you are not a seasoned JS developer or you just don't like coding in JS as a personal preference, then I think these are worth taking a look at. I hear the phrase "just learn JavaScript" quite a bit in regards to these, but I believe learning an API is easier than learning and being proficient in an entire programming language. These tools all have their own approach as well and some are more suited to certain tasks/audiences than others.

artembugara a year ago

Guys, you’re awesome. Congrats on making it to YC.

I’ve been waiting for it as I love streamlit but it’s so limiting.

Happy to help with anything if I can. I’d try to move our next version of our API portal to it

  • jerrygenser a year ago

    What do you mean by making it to YC? I couldn't find evidence of any affiliation

    Do you mean being in hacker news ?

    • artembugara a year ago

      misunderstandling. I thought it's a Launch HN

  • picklelo a year ago

    Thanks so much! We're excited to have people start using it and are looking forward to any feedback :)

FranklinMaillot a year ago

I'm familiar with Anvil, this seems to fill the same niche. Anvil offers a hosted option and lets you design the layout in a graphical interface which makes it compete with low code tools. But this can also become limiting and frustrating. Pynecone seems to have a larger choice of components and they look more polished. I'd be interested to try it to compare.

https://anvil.works/

  • apetuskey a year ago

    Thanks, I prefer the coding ergonomics to Pynecone a lot more vs Anvil. Plus it's easy to for us to add libraries such as bootstrap, material, really any react framework so I suspect we will be able to grow this by a lot in the future. For instance we could have a 3rd party package for bootstrap, or d3js if people want this incorporated.

    Anvil seemed a little outdated for me to personally use but to each their own.

mark_l_watson a year ago

I usually like frameworks with less magic, Sinatra for Ruby, Spock for Haskell, or Flask for Python.

That said, this looks like something I want to try. I learned SwiftUI about 14 months ago, enjoyed writing one app for Apple Store, then didn’t touch it again. I liked the declarative style of SwiftUI and Pynecone seems similar. Am I understanding it correctly?

  • picklelo a year ago

    Yup, our frontend is just a wrapper around React so it is fully declarative. We are definitely more opinionated than something like Flask, but the benefit is that you can write your whole app, including the frontend, in a single language (for small apps just a single file).

TekMol a year ago

"Pure Python" but requires NodeJS?

  • apetuskey a year ago

    This is actually something we are working on getting rid of. What separates us from other python frameworks is that we compile down to a nextjs/react app (the user never sees this though). This is really beneficial because it allows us to add any react library in a matter of hours vs other python frameworks where it can take a much longer time to add new ui feature. Also for performance and SEO nextjs is great.

    But to keep it short there is a way to get rid of this in the future and we are currently working on it. So the only installation step will be `pip install pynecone-io`

    • samwillis a year ago

      This is what I'm trying to solve with this: https://github.com/samwillis/nodejs-pypi

      The idea being that a project like yours can install node into a venv on install for use itself. No more dual stack environments!

      • apetuskey a year ago

        Very cool I'm going to check this out!

  • picklelo a year ago

    Haha fair point. Our goal is that the developer will never see or write Javascript. But behind the scenes Pynecone compiles the app's frontend down to a NextJS app. We're trying to leverage the features of React and NextJS and making them more accessible to the Python community.

matijash a year ago

Congrats on the launch! This reminded me a lot of what we're going for with https://wasp-lang.dev/ (but for the JS/TS domain atm) and I can definitely relate to the problem.

I'm not a big python user but I can imagine how this might be a really friendly way for python devs to build their own apps. The gallery and examples are also nicely done!

dragonwriter a year ago

Single-codebase full-stack in Python is an interesting thing to do, but honestly that API for UI is ugly compared to React or even React-wrapped-in-Python by way of Pyodide. [0]

[0] the approach of this blog post: https://blog.pyodide.org/posts/react-in-python-with-pyodide/

  • jennasys a year ago

    The ugliness is something I struggled with a bit when I was first using Transcrypt to create React applications with Python. Even though that approach is more of a 1-to-1 Python-to-JS mapping instead of a Python wrapper, I felt all the calls to createElement affected readability. But once I started using a Python decorator to wrap the components in createElement, the code got a lot cleaner. Here's a basic example based on the official React tutorial: https://github.com/JennaSys/tictacreact2/blob/main/tictacrea...

abdullahkhalids a year ago

Could I use this to create a static site, which I can serve using my own server?

I like the idea of pure python, instead of messing around with jinja templates.

  • apetuskey a year ago

    Yes I am going to make a blog or something of that nature soon and ill post a follow up on our GitHub discussions.

mring33621 a year ago

From someone who is neither a Python programmer nor a web developer, this looks pretty nice.

Thank you for putting it out there!

  • apetuskey a year ago

    Glad to hear you like it!

digitalsankhara a year ago

Nice work and good luck with future progress.

One thing I could not find, skimming the docs, was where the CSS lives. Could I place my own existing css stylesheet(s) in the project? Would the snake_case equivalents just fall through to the underlying CSS, or would I need to write a CSS dictionary as a translation layer?

Thanks.

  • picklelo a year ago

    Thanks! Yes you can use any valid CSS, see our styling docs: https://pynecone.io/docs/styling/overview. We don't have CSS classes, but you can copy your properties into our snake_case version and pass them to your components.

    • digitalsankhara a year ago

      Thanks. I read the overview and what looked like the lack of support for existing CSS framework and stylesheets prompted my question.

      Unless I'm misunderstanding how CSS support works here, I think this is a deal breaker for me at the moment. Being able to include external stylesheets/frameworks is something of a must have.

      Appreciate it is Alpha level software so look forward to learning how the project evolves.

nier a year ago

I’m wondering how many potentially interested parties are turned off by the errors in this announcement.

An extra with; «Javascript»; «multi page» without a dash; «over 60+»; «you skill level»; or «Open up an issue if you […] contribute to existing issue.»

andybak a year ago

Isn't it going to get expensive offering a free public Dall-E demo using your API key?

  • apetuskey a year ago

    Lol yes our app will probably go down sometime today fyi to everyone

    • nothrowaways a year ago

      Great work! Perhaps you could use other light weight toy examples that don't need API keys. There are simpler models on hugging face, for example.

      • apetuskey a year ago

        Yeah definitely will switch it out just wanted to show a trending model

        • analog31 a year ago

          I'd love to see a graph of some data.

    • nomel a year ago

      Shouldn't it be relatively trivial for someone to get your key banned?

the_cat_kittles a year ago

my advice to people newer to writing software- dont use this kind of stuff without first learning the actual things they try to abstract. with these kinds of libraries, 9 times out of 10 all you get is a more difficult debugging process.

asah a year ago

Curious how testing works... If i could use pytest (somehow) that would be a game changer vs typical frontend testing hell.

dankle a year ago

Better than streamlit??

  • apetuskey a year ago

    With Pynecone you can create full web apps vs streamlit is a little limited in use case and worse performance but to each their own.

    We actually make our whole website and docs in Pynecone where as streamlit could never do this.

    • dankle a year ago

      Nice, looking forward to trying it.

rmorey a year ago

really interesting! compiling to NextJS and keeping it mostly hidden from the user is a smart move. and it uses bun! will be trying this

  • apetuskey a year ago

    Thank you! Yeah we love bun too

jamesdutc a year ago

Congratulations on your release!

Don't let my skepticism (below) to detract from your accomplishment.

I am deeply skeptical not only about this tool in particular but about these tools (e.g., Dash, Panel, Streamlit &c.) in general. I've seen these tools work well for very simple use-cases, but they seem to require some combination of…

· cooperating requirements (matching exactly what the demos do, so you stay completely within the “regime” these tools support)

· upfront knowledge of all requirements (so that you never fall out of this regime)

· the ability to reject requirements (so that you can keep yourself within the regime, though this means the tool is leading the business, not the business leading the tool)

· the ability to accurately identify the boundaries of the regime from the tool documentation and design

For very simple examples, it's may be possible to stay within these constraints, but even when you manage to successfully use these tools, you do so at high (and, in my view, often unacceptable) risk.

In general, the risk/reward for a tool like this is about being able to learn the tool almost immediately (which must also account for time spent trawling through the documentation or the Github issues or even the `dir(module)` to figure out how to spell that one thing you need.) Basically, if you can create something in 1 day that can last for 180 days before a requirement comes along that forces you to start over from scratch, you may be okay.

You certainly never want to become good at these tools; the more you invest in the tooling, the harder it will be to abandon it when it is no longer appropriate, and the more willing you will be to accept contortions that you will inevitably regret. You certainly never want to spend more than a trivial amount of time building something with these tools, since the risk of needing to rebuild or abandon the technology is simply too high.

(Personally, I simply don't think React is that hard to learn, that hard to teach, or that onerous to use…)

In particular, this tool's API seems particularly risky. e.g., in the example code, there is a section like this:

    cond(
        State.mode,
        element,
        cond(
            State.flag,
            other_element,
        ),
    )
So we're encoding the control flow defining the layout in some sort of object graph (some sort of pseudo-AST)? It's not going to take a lot of this to spiral out of control. Unless you can recognize that this tool is unsuitable for even mildly complex programmatic component layout (which is trivial to do in React,) you're going to hit an impassible brick wall trying to handle what will otherwise be considered a benign business request.

I suspect, however, that this API is still being refined. After all, what if I wanted to trigger on two conditions? There are probably some sophisticated `metaclass` mechanisms wrapping the `State` attributes in some symbolic modelling, but SymPy shows us that this is not trivial to get right, and the Python object model constraints you in unpredictable ways. Without looking at the code, I suspect you cannot `cond(State.mode1 | State.mode2, element)` and probably have to create some sort of `State.mode1_or_mode2` subordinate data, which spirals out of control pretty quickly. And what if you want to do `cond(State.mode | mutable_global_mode)`? And so forth and so on.

There are so many structures and modalities for control flow and data flow (trivially expressible in React) that will become clumsier and clumsier to express in with this modelling, and unless you can anticipate that they won't arise, reject the business requirements that mandate them, or (with no regret) throw everything away and start over from scratch, you're going to have a good experience.

  • apetuskey a year ago

    Thanks for the detailed response we really appreciate it and see where your coming from. We definitely are not for everyone but if you want to completely stay in the python ecosystem we are a solid option compared to other frameworks. I think we are in a different class to some of the frameworks you mentioned though because you can actually create fully customizable web apps with us.

    For you react/js was easy to learn but a lot of people don't want to take the time to learn this. At the end of the day every one has a preference and I see where you are coming from on this.

callmeed a year ago

"Pure Python"

"Requires NodeJS"

  • apetuskey a year ago

    This is actually something we are working on getting rid of. What separates us from other python frameworks is that we compile down to a nextjs/react app (the user never sees this though).

    But to keep it short there is a way to get rid of this in the future and we are currently working on it. So the only installation step will be `pip install pynecone-io`

ollien a year ago

Neat! How does this compare to Phoenix/LiveView? Is it similar in principle?

  • picklelo a year ago

    I haven't used Phoenix personally, but it looks similar.

    In Pynecone, the frontend compiles down to a NextJS/React app, and the backend is a FastAPI server. Events are sent as network calls that update the app state, and the state delta is sent back to the React app, which updates the UI.

squarefoot a year ago

Just a heads up that both the name (esp. for non English speaking users) and the quite similar symbol could possibly clash with the Pinecone by Pine64.org.

https://wiki.pine64.org/wiki/PineCone

kgbcia a year ago

looks fantastic, wish this was the direction of webapp development

andybak a year ago

Auto-reload of "pc run" on any edits please!

  • picklelo a year ago

    This should already be a feature! (Let me know if you're running into issues). We enable hot-reloading of the app when you save your file.

andybak a year ago

Any plans for three.js or any kind of WebGL component?

  • apetuskey a year ago

    Definitely we can add any react library just submit a feature request on our GitHub issues and ill get on it

SleekEagle a year ago

Is this only for ML projects? Is it a Gradio wrapper?

  • apetuskey a year ago

    No definitely a much broader use case and we compile to nextjs/react and have nothing to do with gradio. With tools like gradio and streamlit you are very limited in use case. With Pynecone you can make full scale multipage web apps in pure Python that are completely stylable and customizable

augasur a year ago

I will love to try it out!

How does it compare to Flask framework?

  • boxed a year ago

    Flask is just a tiny API for http. It doesn't even do templating.

thatwasunusual a year ago

Sorry, but when you do templating inside the code you lose me immediately. I expect a reply like "but you don't have to", but damage is already done.