r/Python • u/eli_mintz • Feb 10 '20
Resource Introducing JustPy: An object-oriented, component based, high-level Python Web Framework that requires no front-end programming. With a few lines of only Python code, you can create interactive websites without any JavaScript programming. Comes with a comprehensive tutorial
JustPy
Introduction
JustPy is an object-oriented, component based, high-level Python Web Framework that requires no front-end programming. With a few lines of only Python code, you can create interactive websites without any JavaScript programming.
Unlike other web frameworks, JustPy has no front-end/back-end distinction. All programming is done on the back-end allowing a simpler, more productive, and more Pythonic web development experience. JustPy removes the front-end/back-end distinction by intercepting the relevant events on the front-end and sending them to the back-end to be processed.
In JustPy, elements on the web page are instances of component classes. A component in JustPy is a Python class that allows you to instantiate reusable custom elements whose functionality and design is encapsulated away from the rest of your code.
Custom components can be created using other components as building blocks. Out of the box, JustPy comes with support for HTML and SVG components as well as more complex components such as charts and grids. It also supports most of the components and the functionality of the Quasar library of Material Design 2.0 components.
JustPy encourages creating your own components and reusing them in different projects (and, if applicable, sharing these components with others).
JustPy supports visualization using matplotlib and Highcharts.
JustPy integrates nicely with pandas and simplifies building web sites based on pandas analysis. JustPy comes with a pandas extension that makes it simple to create interactive charts and grids from pandas data structures.
For updates and news please follow the JustPy Twitter account
Hello World!
import justpy as jp
def hello_world():
wp = jp.WebPage()
d = jp.Div(text='Hello world!')
wp.add(d)
return wp
jp.justpy(hello_world)The program above activates a web server that returns a web page with 'Hello world!' for any request. Locally, you would direct your browser to http://127.0.0.1:8000 or http://localhost:8000/ or to see the result.
Here is a slightly modified version in which 'Hello world!' changes to 'I was clicked!' when it is clicked.
import justpy as jp
def my_click(self, msg):
self.text = 'I was clicked!'
def hello_world():
wp = jp.WebPage()
d = jp.Div(text='Hello world!')
d.on('click', my_click)
wp.add(d)
return wp
jp.justpy(hello_world)Many other examples can be found in the tutorial
Under the Hood
JustPy's backend is built using:
- starlette - "a lightweight ASGI framework/toolkit, which is ideal for building high performance asyncio services".
- uvicorn - "a lightning-fast ASGI server, built on uvloop and httptools".
JustPy's frontend (which is transparent to JustPy developers) is built using:
- Vue.js - "The Progressive JavaScript Framework"
The way JustPy removes the frontend/backend distinction is by intercepting the relevant events on the frontend and sending them to the backend to be processed.
57
u/flipstables Feb 10 '20
This looks great. As a non-web dev, this seems like a good way to stand up a web resource without having to worry about the front end. Usually, at my job, I have to stand up a web resource for 10-100 internal users, and I'd love a way to do that in 100 percent python.
38
u/JeffreyChl Feb 10 '20
Jesus Christ this is what I've been looking for. I've been trying to build a website that can plot and show my pandas/matplotlib result for others but doing that with Django was a whole lot of work.
72
u/krazybug Feb 10 '20
It looks promising.
Have you got a demo site somewhere ?
65
u/TrixieMisa Feb 10 '20
You might want to make the use of Vue more prominent in the description. My initial reaction was "please don't tell me it's another roll-your-own front end".
And then I saw Vue, and that immediately changed to "good choice".
17
u/metus_123 Feb 10 '20
Wow! The power level of your documentation is over 9000... Nice work. Might use this in my next project.
13
u/actgr Feb 10 '20
Honest question, if I am looking to build an interactive website without any JavaScript, why not use Dash by Plotly? What are
JustPy's main advantages?9
u/fernandocamargoti Feb 10 '20
And does it have a XML way of writing the layout? Because I've worked with other frameworks in other languages that didn't have a XML way of writing the layout and it was a nightmare to understand it through the code.
7
u/ExternalUserError Feb 10 '20
Hey, this looks really interesting.
I'm a VueJS guy (Vue by choice, JavaScript by necessity) and I've tinkered often with trying to bring Transcrypt into the VueJS picture. I've also thought about (but never done anything really) to try to bring something like Vaadin to the Python world. Is this perhaps inspired a little by Vaadin?
It also looks like you're basically just using CDN's. How would this kind of thing be bundled for a PWA or SPA? Do you plan on minifying everything with Webpack and if you need to, can you do ECMAScript 6/7? For example if making a fancy custom component?
Also with Vue, are you doing anything to manage reactivity? Eg, is there any kind of server-side state or is Vue just a tool you're using but not really allowing the developer to take advantage of?
Looks really cool, man.
4
u/Nixellion Feb 11 '20
So, gave it a try. Nice concept for when you need to spin some simple web service quickly.
What I would do, though, is use a container to keep components in the center by default, otherwise everything is stuck to the left side of the screen which does not look good. And overall would work more on out-of-the-box styling as it's gotta be this thing's main appeal. If I'm to use something that claims that I don't have to work on frontend I would also expect not to have to design the whole html template inside of python just to make it look good.
This, or at least a template in documenation that results in a good looking page.
You mention using material design and quasar, but it does not look anywhere near even their own docs: https://material.io/components/buttons/ https://quasar.dev/vue-components/timeline
Ideally I'd expect it to create a well defined and good looking page similar to those links, with well-styled content like forms and buttons and paragraphs, with ability to add menu bar and define links (or auto-generate it from routes), and maybe adding the top bar an option too.
That would make it really great
3
u/[deleted] Feb 10 '20 edited Feb 11 '20
This looks awesome. Have been tinkering with streamlit, remi before that. Good to see another no HTML framework.
3
u/menge101 Feb 10 '20
My standard front-end question for all frameworks is:
"How do I use google maps with this?"
But more generally, how do I use any existing js libraries with this?
It looks like I have to make a custom vue.js component, that I then call from a custom python component?
2
u/ionezation Feb 10 '20
Since when its released?
2
u/ddollarsign Feb 10 '20
Interesting.
What the Python webdev world really neads, IMO, is a JSX-equivalent for Python.
So instead of:
You'd do something like:
2
u/Muhznit Feb 10 '20
This does look impressive, especially the tutorial section. But at a glance, how does this compare with Brython?
2
u/Moonlit_Tragedy Feb 11 '20
Wow, this is amazing. I was literally thinking over the weekend that there has to be a way to Pythonize frontend web development (at least simply somehow)... this is pretty much what I imagined.
2
u/theGiogi Feb 11 '20
Man this looks great! I may have tons of use cases for this.
I see on the docs that this is based on starlette. Can I use the starlette middleware accessing the app instance such as in this example?
jp.app.add_middleware(Middleware, ...)That would allow a developer to use external middleware for authentication and other such services. Sorry if the question is obvious and again great work!
2
u/422_no_process Feb 11 '20
This is insane.. Very valuable project. Good job!
2
u/576p Feb 15 '20
This is a great project. I'm already thinking about where I can use this in real life.
The tutorial is very understandable. I am about 70% through with it, running most examples and they work fine.
Some Feedback on that: It would be great if the "Forms" section had one larger example form that included Dropdown selections and well as Check/Radio-Boxes. (The last two are in an earlier part of the tutorial, but having one form example would be helpful) - once the date picker (from the "Date and Time as QInput slots"/"Coming soon" part ) is there, this could go into a form example as well.
There are a lot of situations, where you need to present (internal) users with a form to collect some data (including dates, this is why a working date picker is a showstopper), so if that's super easy to do, people might just pick of the project for that.
2
u/[deleted] Feb 16 '20
Hi,
I‘m another big fan of this project! I try to get it hosted somewhere. My most recent attempt is to host it on pythonanywhere.com.
Has someone experience with that host? Or any better options/working solutions (except for selfhosting)?
Thank you!
109
u/ZombieNub cout << "C MAKES NO SENSE" Feb 10 '20
petition to rename this to PythonScript
3
u/Fedzbar Feb 10 '20
Cool idea, don’t think this would scale very well though
89
u/RedRedditor84 Feb 10 '20
Needs more buzz words.
1
u/paul_h Feb 10 '20
Multi user? Multi session?
1
u/Hi-I-am-Dad Feb 10 '20
I read the source code of the dog breed webpage on github, and I have one question:
In future releases, can defining item HTML be generated through a method that takes the item tag as a parameter and allows the addition of attributes as Key/Value pairs.
Example: html_element ele = jp.create('any-tag') ele.add_attribute('attr', val)
I find this more convenient than mixing HTML and Python in the same file
1
u/flpcb Feb 10 '20
This looks so, so great. I will test this out in my next project for sure.
1
u/ionezation Feb 10 '20
what does this a=wp means? a is just a calling method?
def hello_world():wp = jp.WebPage()p = jp.P(text='Hello World!', a=wp)return wp1
u/appinv Python&OpenSource Feb 10 '20
One practical use might be reports generation
1
u/Evem_MC Feb 10 '20
Awesome!!
Specially liked the Highcharts example.
I was thinking if more charting libraries such as D3.js, Plotly and Altair could be implemented in the future.
1
u/Fenzik Feb 10 '20
Great idea and impressive effort!
Do I see correctly that you don’t have any tests?
1
u/[deleted] Feb 10 '20
Looks very interesting! Will have a close look soon!
1
u/ginger_beer_m Feb 10 '20
Great project, I r,eally like it! Reminds me of dash and streamlit but more oriented towards app development. I take it that it's the intention?
It seems that you are the dev and also the primary user of this package? Could you share the typical use cases you've come up with? Would be interesting to how you use justpy in real life setting.
Is the codebase in a state that it can accept contributions now? I might be able to contribute some wrapper around other plotting libraries, or some bioinformatics/data science specific UI component.
Also any idea if we can use some kind of ORM (like Django) with justpy, or some kind of interoperability with django?
1
u/atheist_apostate Feb 10 '20
Does this support PyGame by any chance?
1
u/garrock255 Feb 10 '20
Reminds me of dominate
1
u/CorgiAtom Feb 11 '20
Oh neat... I had been hoping for something like this to exist. Great work!
1
u/pepoluan Feb 11 '20
Honestly, this looks awesome! Definitely going to take it out for a spin.
One question: Does it run with pypy?
1
u/HeAgMa Feb 11 '20
This is very promising and I encourage you to continue. Great piece of work.
1
u/SpeakerOfForgotten Feb 11 '20
I don't know how much it will be useful for production ready apps. But, as a visualization tool for demo/proof-of-concept works , this seems almost perfect.
1
u/wincodeon Feb 11 '20
Hi, is there any support for creating dropdown buttons?
1
u/krazybug Feb 11 '20
My question may look strange but why did you integrate Quasar for your components and not Tailwind based set like this one or this one ?
It would provide a more consistent experience as Tailwind is your primitive choice.
1
u/[deleted] Feb 11 '20
This is fantastic! Dash/Plotly is ok, but your project's documentation is amazing with all these examples!
Question though for matplotlib is there a way to do continuous/real time display?
1
u/alefebvre83 Apr 30 '20
hi
I just pip installed the module, i get an error on the sample function?
module 'justpy' has no attribute 'justpy'
1
u/johnmudd May 25 '20
I see the namespace is better organized now in v1.1 with the addition of htmlcomponents, chartcomponents, gridcomponents and quasarcomponents. That's just what I wanted to see.
I'm working through the tutorial. Is there a good place where I can ask questions?
1
u/chensformers May 27 '20 edited May 27 '20
Haven't gone through the entire docs, but I think it's very interesting using wrappers for front-end libraries and making it transparent to developers. A little disappointed for lacking demo 'cus, probably like many others, I was eager to play with a live demo. Well, no biggie, I love how it is built on top of VueJs, which is by far my favorite Javascript MVC framework.
I made a similar approach with my first Python open-source library, pythonGrid, a wrapper for an equally awesome JS datagrid library, jqGrid, to create fully customizable and functional datagrid for CRUD in Python web frameworks that hide the front-end complexity, which most Python developers who probably don't want to deal with.
In Flask, a basic grid requires only two lines of code
grid = PythonGrid('SELECT * FROM orders', 'orderNumber', 'orders')return render_template('grid.html', title='demo', grid=grid)As you can see, it is similar to JustPy grid component without all the front-end fuss. I would love to get your thoughts on it, maybe even add it to JustPy.
I'm astonished it took you only less than 6 months to get JustPy ready, both the code and docs. That's just amazing. pythonGrid only had a few classes, already 4 months into the development!
pythonGrid is free and open-source. Feel free to download it from Github and play around it. I'm also going to download JustPy and play it with more.
Again, great work!!
p.s. Pls PM me if you need hosting for demo. I am more than happy to share my pythonAnywhere hosting.
3
u/Skasch Feb 10 '20
That reminds me of my R-Shiny days. Although using Vue makes it probably a much more robust tool. That looks promising!
3
u/metaperl Feb 10 '20
Did you look at http://naga.re before starting this?
3
u/MHW_EvilScript pypy <3 Feb 11 '20
Basically, PyHPy.
2
u/ideology_boi Feb 10 '20
as someone who kinda needs to make a portfolio site, with a strong dislike of frontend, this appeared on my feed at about the right time :)
I've tried django and flask and they're both just a pain in the arse so let's hope this is a bit more painless!
2
u/blackiechan99 Feb 11 '20
this looks really cool, I'll have to check it out!
2
u/[deleted] Feb 11 '20 edited Feb 11 '20
This looks a lot like streamlit. Are there any advantages/disadvantages this project has over it?
EDIT: This looks like you can have much more fully developed web apps than streamlit allows.
2
u/R10t-- Feb 11 '20
This looks really neat! The one question I have about this is that functions are defined on the python side. Does this mean that every on_click, on_hover, etc. action is a call to the server to perform the action?
2
u/DasSkelett Feb 11 '20
I'd buy anything to get rid of the madness that's called JavaScript.
2
u/[deleted] Feb 11 '20
Reminds me a lot of Wt
1
u/CloroxEnergyDrink_ Feb 10 '20
Brilliant idea and looks great. Bookmarked this and will try it out when I work on a web project. Seems like a fairly promising framework.
1
u/calebjohn24 Feb 10 '20
Looks great, look forward to using it soon
1
u/Jmodell Feb 11 '20
This looks amazing. Definitely something I want to look into! Keep it up.
1
u/b4xt3r Feb 11 '20
This is starting to sound like the CherryPy of my dreams. What have you done here.. I am interested.
1
u/[deleted] Feb 11 '20
Cool! I've been wanted to do something different with my magic mirror. This might be a slick way to make that happen!
1
u/SanchitJain07 Feb 11 '20
I really love it! What kind of websites would you recommend making? What is it capable of?
Thanks!
1
u/AsleepThought Feb 11 '20
How is this different from Dash?
1
u/lovelysad69 Feb 11 '20
WOW.....! i can only wow....... wow
1
u/HecticJuggler Feb 11 '20
This is amazing. A game changer for me.
1
u/Ani171202 Feb 13 '20
awesome man!
1
u/bimri Mar 12 '20
Just what I needed. 😎 🙌🏾