Adding Database Backed User Authentication to FastAPI

🔖 code  python  fastapi 

So you’re excited about FastAPI and you’ve been following the excellent documentation. At some point, you’ll come to the section on security which sets you up with a login view, some utilities for hashing passwords and a dependency injected current user object.

It works great! The only problem is now you are left with a working application, but your user database consists of a hardcoded dictionary. Obviously, this will not do for a real application.

In this tutorial, we will replace our fake users database dictionary with a real database backed user table. In the next part, we’ll add a registration endpoint so that people can sign up for accounts and login to your application.


Switching from Disqus to Commento

🔖 code 

This website has been following the blog software hype train since it’s inception. The progression went like so:

  1. Facebook “posts” (discontinued)
  2. Blogger
  3. Blosxom - a very early static site generator, way ahead of it’s time.
  4. Wordpress
  5. Jekyll
  6. Hugo (current)

At the transition between Wordpress and Jekyll, like many others, I needed a solution for comments on a static site and Disqus was the clear choice. But then many of us learned that by using Disqus, we were allowing ads to be placed on our own pages. We were bogging down our websites with loads of third party trackers and possibly even violating our own reader’s privacy.


Flask or Django? Which to Choose for your Project

🔖 code  django  flask  python 

Often I get asked by fellow python developers why I chose Django/Flask for a particular project (usually by someone who prefers the framework I didn’t choose 😉). I think both frameworks are excellent and are well suited for a variety of use cases.

So how do I decide which to use for a new project? I found a simple heuristic to get 90% of the way to a final decision, and it’s pretty easy to follow:


Essential Django Apps for Every Project

🔖 code  django  python 

Django projects have the ability to install apps, which are analogous to plugins in other frameworks.

Some of these apps provide simple functionality: django-gravatar installs a template tag for displaying a user’s gravatar in a template. Other apps are large, like Mezzanine which provides an entire CMS framework to your project.

No matter what you are building, you should consider the following apps. I use them in almost all of my projects.


A Not so Dramatiq Change: A Celery Alternative

🔖 code  astronomy 
Both Celery and Dramatiq are asynchronous task processing libraries. You’d use them when you want to be able to parallelize Python code, and you need more than the multiprocess module offers, like persistent distributes queues, automatic retries, and result handling. I’ve been using Celery for almost my entire career, and it’s treated me well. Recently I’ve started to become frustrated with it. There have been numerous regressions that have broken my code, as well as some totally inexplicable issues in the last few months (that last one is the reason I started looking for alternatives). Read more...

Line by Line Simple but Usable VIM Config

🔖 code 

VIM is a great editor, but it’s defaults are a little lacking. Fortunately it’s also extremely configurable. This leads many people (myself included), to scour the internet for lines of internet wisdom to copy in paste into their .vimrc files until they get something that works for them. Before you know it you have 300 lines of unintelligible gobblegook. In this post, (which I’ve started writing in vanilla vim) I’m going to go line by line through individual config items to construct a simple but usable .vimrc without too much magic or frills.