News for hackers. Stuff that matters.

Ask HN: What Python web programming frameworks and tools are you using?

I'm interested in hearing from the community about what tools you are using for building web applications in Python.

So, what tools, databases, web servers and frameworks are you using for your latest Python web application projects? Or, if you've abandoned Python, what language have you moved to, and why?

( 14 comments | 11 points | on HN )
Re:Ask HN: What Python web programming frameworks and tools ... by thinkxl on Thursday February 22, 2018 @12:01PM (#16439060)
Bottle[0], Dataset[1], and pipenv[3].

With those three tools I can create a web app with basic functionality with few lines of code, like a prototype. For example:

  from datetime import datetime
  from bottle import get, post, request, run, template, redirect
  import dataset


  db = dataset.connect('sqlite:///database.sqlite')
  entries_table = db['entries']


  @get('/')
  def show_entries():
      entries = entries_table.all()
      entries_sorted = sorted(entries, reverse=True)
      return template('entries', entries=entries_sorted)


  @post('/add')
  def add_entry()
      entry = request.forms.get('entry')
      entries_table.insert(dict(
          text=entry,
          created_by=datatime.utcnow(),
      ))
      return redirect('/')


  run(reloader=True, debug=True)
- [0] https://bottlepy.org/docs/dev/

- [1] https://dataset.readthedocs.io/en/latest/

- [3] https://docs.pipenv.org/

Edit: formatting.

Re:Ask HN: What Python web programming frameworks and tools ... by vram22 on Friday February 23, 2018 @11:24AM (#16447272)
Where is the code that shows (in the browser) the form for add_entry()? I've used Flask, and for a task like this, you typically have to have either one method which is decorated with a route that takes a list of two method args, "get" and "post" in a list, and then have an if statement to distinguish between code to display the form (get code) and code to process the data on submit (post code), or two separate methods, which could be called get and post or get_entry and post_entry. But your get method does not show a form; it displays all the entries.
Re:Ask HN: What Python web programming frameworks and tools ... by thinkxl on Friday February 23, 2018 @12:34PM (#16447806)
In that example I put the form on the '/' route. Here is a GitHub repo with the code:

https://github.com/thinkxl/hn-bottle-example

And here is a gif showing how it works:

https://dsh.re/364b2

Edit: Words.

Re:Ask HN: What Python web programming frameworks and tools ... by vram22 on Friday February 23, 2018 @02:37PM (#16448731)
Okay, will check those out, thanks.
Re:Ask HN: What Python web programming frameworks and tools ... by cpburns2009 on Thursday February 22, 2018 @12:41PM (#16439451)
For websites and internal web applications I use the following.

Framework:

- A bastardized modification of Django (bad choice, but I'm stuck with it). I'd really like to try Pyramid or Flask.

- Mako for templating.

Databases:

- PostgreSQL for primary data storage.

- Solr for full-text search.

- Redis for cached data.

Servers:

- Nginx for the front-end server.

- uWSGI for the application server (bridge between Nginx and Django). I'd like to try Nginx Unit.

Browser-side:

- jQuery for functionality.

- Bootstrap for base styles.

Re:Ask HN: What Python web programming frameworks and tools ... by thinkxl on Thursday February 22, 2018 @01:02PM (#16439699)
Flask is really cool. It has a great community and a package for everything you'd need.
Re:Ask HN: What Python web programming frameworks and tools ... by odonnellryan on Thursday February 22, 2018 @03:32PM (#16441116)
I use Flask in most of my projects, the source is very fun to read.
Re:Ask HN: What Python web programming frameworks and tools ... by pkaura on Thursday February 22, 2018 @02:17PM (#16440486)
Django, DRF(usual suspects), django-silk from profiling API's. Pycharm is my IDE of choice.
Re:Ask HN: What Python web programming frameworks and tools ... by siquick on Thursday February 22, 2018 @06:16PM (#16442493)
Flask if building APIs, Django if building CRUD sites.

I write all my database commands in raw SQL rather than using an ORM, primarily because it's far quicker for me to write slightly more complex SQL than manipulate objects.

Re:Ask HN: What Python web programming frameworks and tools ... by potta_coffee on Thursday February 22, 2018 @06:50PM (#16442741)
I'm a big fan of Flask. For more performance oriented projects I'm dabbling with Go, going to attempt a non-trivial project with it soon.
Re:Ask HN: What Python web programming frameworks and tools ... by rsinger87 on Friday February 23, 2018 @12:34AM (#16444455)
Django with Django REST Framework. Postgres for DB, Redis for caching. RQ/Django RQ for background tasks. OpenAPI for API documentation.
Re:Ask HN: What Python web programming frameworks and tools ... by tobaschco on Thursday February 22, 2018 @09:46PM (#16443782)
Django all the way.

Use the built-in admin functionality for easy CRUD, and add the django-rest-framework plugin for a full REST api as well.

Re:Ask HN: What Python web programming frameworks and tools ... by ryanchants on Thursday February 22, 2018 @12:29PM (#16439332)
I'm currently working on a web2py app that I'm working to convert to Django.
Re:Ask HN: What Python web programming frameworks and tools ... by aprdm on Thursday February 22, 2018 @09:12PM (#16443637)
flask via flask_restplus

SQLAlchemy for ORM

PostgreSQL/Redis/Elasticsearch for storage