Why Python Beats HTML+JS for Web Development
Web development is pretty unwieldy. You need to master JS and HTML and CSS and Python (or Rails or Node) and a ton of frameworks.
We love Python because of its motto: Simple is better than complex. So what would web development look like, if it were 100% Python -- even the front end? We built it, and it's called Anvil.
Here are 12 reasons why building your front-end and back-end in Python is so great:
1. Your UI components are all Python objects.
Running Python in the browser means you can modify your UI components in Python. Drag and drop them onto the page to build the user interface, then set their properties and call events on them from Python code.
Building the UI for a feedback form. Check out the tutorial!
2. Call server-side functions from the browser
In traditional web-dev, calling from the browser to the web server is a pain. You have to set up a URL route, smush all your data into JSON, set up the AJAX request, asynchronously get a response...so much work!
With Anvil, you just call a function. Add a decorator to any function, then just call the function from browser code. Pass Python objects as arguments; return Python objects. Job done.
3. The database is built-in
Setting up and maintaining a database is a drag. So Anvil has a built-in database. Design your data tables graphically, then query or update rows with Python. (Can you return a lazy paginated query response to the browser, as a Python object? Of course you can! That would be dozens of lines of code in most web frameworks.)
4. Connect your code running anywhere
Anvil is "serverless" - your code is automatically hosted in the cloud. But what if you want to run code on your computer? Just use the Uplink!
Got a Jupyter notebook? Call it from the web!
Got a local database? Write a local script to query it, then call it from the web!
Connecting a Google Colab notebook to a web app
5. Binary data is easier to handle
"Uploading a file" is basic functionality. So it must be simple in every web framework. Right? Surprise! Handling binary data -- like files, images, or PDFs -- is remarkably difficult in a traditional JS app. (If you're feeling mean, try saying 'enctype="multipart/form-data"
' to a seasoned web developer. Watch them shiver.)
But Anvil makes it easy. All binary data (pictures, uploaded files, etc.) is represented as a Python object! You can pass binary data as an argument to a server function. You can store it in a Data Table. You can use it with Anvil components. For example, rendering and downloading a PDF is literally this simple:
# In a server module:
@anvil.server.callable
def get_pdf():
return anvil.pdf.render_form('Form1')
# In the browser:
pdf = anvil.server.call('get_pdf')
download(pdf)
6. User authentication comes built-in
Building user authentication is tedious, but deadly if you get it wrong! Half of the OWASP vulnerabilities are "ways you can get authentication wrong".
Anvil's built in User Service handles signup, login, and user permissions for you, out of the box. It takes one line of Python code to present your users with a signup form with email validation -- just call anvil.users.login_with_form()
.
As well as email login, Anvil supports Google, Microsoft, Facebook, and SAML SSO. (What about two-factor authentication? Of course it works.)
7. Email support is built-in too
Send an email with one line of code. Receive emails with one line of code! It's all built in with Anvil's Email service.
Building an app to receive email is so simple, we did it in a 4-minute video:
8. PDF generation is also built-in
Did someone say "batteries included"? Create PDF documents with our drag-n-drop editor, then render and download them with a Python call.
9. Use your favorite Python packages
One of the best features of Python is the numerous packages available. With the Full Python runtime, you have access to a long list of your favorite Python libraries to build your web apps.
10. You can still build HTTP APIs
Want to build an HTTP API, so non-Anvil apps can interface with your service? Creating HTTP endpoints is nearly as simple as making functions you can call from the browser. Check out this tutorial.
Or just watch Bridget build and deploy a JSON API in 20 seconds:
Creating and deploying a working JSON API in 20 seconds.
11. One-click integrations
Your Anvil app can easily connect to services from Google, Microsoft, Facebook, Stripe and more. Log your users in using Google, Microsoft and Facebook Single Sign-Ons, take payments with Stripe, or display interactive Google Maps.
12. Easy encrypted storage
You don't want to leave passwords lying around in your source code. The App Secrets service provides easy-to-use encrypted storage of sensitive data, like passwords or encryption keys.
Learn to store encrypted data with another 4-minute tutorial:
Get Simple. Keep the Power.
Anvil gives you all the power of Python, and none of the complexity of traditional web frameworks. If you're a Python developer, you can build full-stack web apps without needing anything else.
And if you do want to tweak something with HTML, CSS or JavaScript, there's always an escape hatch! Use a Javascript library from Python code, or style your app with HTML CSS.
Don't get locked in.
Anvil's runtime is open source, so you can take your app and deploy it anywhere. You don't even need our editor to create an Anvil app!
Start Building
Anvil is free is to use, so you can start building right away! Start with a tutorial to get acquainted with Anvil or check out the documentation to learn about some of Anvil's other features.
Top comments (6)
This is a super interesting product! As a budding dev, I've been learning Javascript and am just getting my feet wet with Python. I love how straight forward the syntax is but it makes me wonder...how does Anvil do on performance? While great for data management and processing, it's been noted that Python's speed is slower than Javascript. Does anvil support the shadow DOM? I really like the modular approach with web components and how much easier it is to manage DRY styling with SCSS. It would be a dream to streamline building with those technologies and Python!
Well, you're asking the right person - I'm a maintainer of the Skulpt Python-to-JS compiler we use!
The answer is that, inevitably, compiling Python to JS comes with a performance hit. Our responses are twofold: First, we're narrowing the gap, by improving the compiler/toolkit speed (one example: we just landed a deep refactor of Skulpt that speeds up compiled code 2x!). Having said that, front-end Python performance often isn't the bottleneck to making an app feel snappy - it's usually about, eg, being smart about how you load data from the back end.
Second, if you need to do something in JS, you can! Anvil supports calling JS objects from Python, and vice versa (see my Christmas DEV post where I build a 3D model with THREE.js). This means that you can build your whole app with Anvil, and if some part hits a performance limit (or any other limit), you can rewrite that particular component in JS. This is part of our philosophy of always offering an escape hatch -- if you need to go low-level, you can.
In a world opinionated tools, I love the incorporation of an escape hatch! Often as a beginner, what starts off as a simple low level experiment, quickly whirlwinds into a much bigger undertaking what with trying to wrangle so. many. frameworks. Thanks for taking the time to answer to my questions. Off to play!
This looks freaking amazing! how did I not know about this?
Glad you like it!
Tip: If you ever find yourself asking, "How did I not know about that?", you can help fix it! Think back to all the places you could have found it, and mention it there! That way, the next person will find that information sooner.
This rule is great for your codebase: if nobody told you how to set up a dev environment, and you had to figure it out yourself, take all the steps you just learned and add them to
README.md
! It also works for your community: if you'd have expected to find Anvil on Reddit, or DEV, or your favourite Slack community, post a link there for the next person!I try the little demo and I have to admit it is impressive.