Back to blog
FastAPI

Testing

In this blog post, I share my journey in building a FastAPI auth starter code, highlighting the common dilemma software engineers face: whether to use an existing library or build a custom solution. While libraries like fast-sso offer quick and reliable solutions, they may not always fit the unique needs of every project. Recognizing this, I created a FastAPI auth starter that provides the best of both worlds—quick setup and flexibility. This starter code is designed to help developers save time and adapt to various types of applications, from small projects to complex SaaS products. Whether you need basic authentication or more advanced roles and permissions, this starter code can give you a head start. The post emphasizes the importance of choosing the right tool for your project, team, and goals, and encourages developers to consider both libraries and custom solutions based on their specific needs.

Alim··5
Testing

Building a FastAPI Starter

As a software engineer, I've learned that problem-solving in development rarely involves finding a single correct answer. Sometimes, you rely on a tried-and-tested library, refined by many before you. Other times, you need something tailored specifically to your project, so you roll up your sleeves and build it yourself. That's the decision I faced when building authentication for a FastAPI app.

The Challenge: Library or Custom Solution?

I needed to set up authentication fast—really fast. As I brainstormed, two clear paths emerged:

Use an existing library like fastapi-sso: Excellent for quickly integrating single sign-on (SSO) or managing user authentication with minimal fuss.
Write my own authentication starter: More flexible and adaptable to various app types.

Initially, using a library seemed the obvious choice. Why reinvent the wheel? Well-maintained solutions already exist. However, the more I pondered, the more I realized not all apps have the same needs. Sometimes, a one-size-fits-all library isn't quite right. That's when I decided to build my own FastAPI auth starter.

Why I Decided to Build My Own

Building applications always involves some form of authentication setup. It's necessary but can be a hassle to do from scratch every time. Libraries like fastapi-sso can quickly implement authentication, which is super convenient. But what if your app doesn't fit neatly into that framework? What if your project requires more flexibility or control over authentication?

That's where the idea for my FastAPI auth starter came from. I wanted to build something that could:

Get you started quickly by providing a reliable authentication system you can set up in minutes.
Be flexible enough to work with all kinds of apps—from simple to complex.

It's similar to when I built my blog. Instead of creating my own CMS from scratch, I chose Notion as the CMS. It's powerful, well-maintained, and even has AI tools to help make content more SEO-friendly. I integrated it with Redis and Notion DB for speed and efficiency, resulting in a system that worked better than anything I could have built from scratch. It saved me time and let me focus on writing content, not building infrastructure.

The same thinking applied to authentication: sometimes, you need a solution that just works—but you also want to tweak things if needed.

The Benefits of Libraries

Don't get me wrong—libraries like fastapi-sso are fantastic for many situations. Here's why libraries can be so helpful:

1. Time and Resource Efficiency

Libraries save development time. Instead of spending hours writing basic functionality, you can use a pre-built solution and focus on what makes your app unique.

Faster time-to-market: Libraries let you deliver projects quicker, a game-changer for startups and businesses launching MVPs or prototypes.
Avoid reinventing the wheel: Many common problems are already solved by well-maintained libraries. You don't need to write code from scratch when someone has already done it.

2. Proven Reliability and Stability

Popular libraries have been used by thousands of developers, meaning they're tested, stable, and reliable. You're less likely to encounter bugs with a well-known library than if you build from scratch.

3. Reduced Maintenance Overhead

Using a library also alleviates some long-term headaches. Library maintainers handle updates, bug fixes, and compatibility patches, so you don't have to.

Regular updates: Libraries are frequently updated to stay compatible with the latest frameworks and languages.
Focus on core features: When you use a library for something like authentication, you free up time to work on the core features that make your app special.

When Custom Code is the Better Option

Despite all the benefits of libraries, there are times when writing your own code is the better choice. That's why I ended up building my FastAPI auth starter. Sometimes, libraries just don't provide the flexibility or control you need.

1. Meeting Specific, Unique Requirements

Every project is different. If your app has unique needs, writing custom code ensures that the solution fits perfectly, without compromises.

2. Performance Optimization

Libraries often come with extra features you might not need, which can lead to performance overhead. Custom code lets you optimize everything precisely for your app's needs.

3. Complete Control Over Your Codebase

When you write custom code, you have full control over every aspect. That means it's easier to debug, optimize, and modify when necessary.

4. Fewer External Dependencies

Libraries can introduce potential risks, like security vulnerabilities or version conflicts. By writing your own code, you reduce these risks and dependencies.

My FastAPI Auth Starter: The Best of Both Worlds

So why did I build this starter? It was about combining the best aspects of both approaches. I wanted to give people a quick, flexible, and customizable way to add authentication to any FastAPI project, without the overhead of complex libraries or the need to build everything from scratch.

Quick setup: Get authentication up and running in minutes.
Flexibility: Adapt the starter code to fit your project's unique needs.
Control: You're not tied to a third-party library's constraints or limitations.

How You Can Use It

If you're starting a project and don't want to spend hours setting up authentication, my FastAPI auth starter is here to help. Whether you're building a small app, a SaaS product, or a larger platform, you can easily customize it to fit your needs.

And if you prefer to use something like fastapi-sso, that's great too! Both paths are valid—it's all about what works best for you and your project. But if you need flexibility and control, give my starter a try.

The Bigger Picture

In the end, the choice between using a library or writing custom code isn't black and white. It depends on your project's scope, your goals, and how much flexibility you need. Sometimes, it's best to lean on the strengths of a well-maintained library. Other times, building your own solution is the way to go.

With my FastAPI auth starter, I wanted to give developers a middle ground—a solution that offers both speed and flexibility. I hope it saves you time and helps you focus on building amazing software, just like how using Notion for my blog allowed me to focus on writing instead of building a CMS.

So, if you're starting a new project and need a quick way to set up authentication, give it a try. I built it to help others move faster and have the flexibility they need.

GitHub Project

You can find the FastAPI auth starter code on GitHub:

FastAPI Auth Starter on GitHub

Feel free to fork the repository, open issues, or submit pull requests. Contributions are welcome!