Code Challenge 61 - Build a URL Shortener

PyBites, Thu 21 February 2019, Challenge

challenges, code challenge, code review, Flask, github, mentoring, PR

There is an immense amount to be learned simply by tinkering with things. - Henry Ford

Hey Pythonistas,

Changing the PCC game a bit

Let's be honest: we slacked off a bit on our blog code challenges! Apart from the increased workload overall, our synchronous approach of solving a challenge before launching a next one, is holding us back.

So we are going to change our approach a bit. We're going to keep launching PyBites Code Challenges (PCCs) on our blog, because most importantly this is what gets YOU to write Python code!

However we are dropping hard deadlines and review posts. Solving them is an ongoing thread and you can see merged solutions on the community branch (each challenge # has a dedicated folder).

You can collaborate with each other on our Slack (= dedicated #codechallenge channel). And of course keep PR'ing your code via our platform.

Want to code review / become a mentor?

We are still getting a pretty manageable number of PRs to be able to merge them all in ourselves.

However we think it would be really cool to give each PR a bit more of a code check. Hence we also want to make this a community effort.

So if you want to help out merging PRs into our challenges branch, become a moderator. You can volunteer on Slack.

It's a great chance to read other people's code honing your code review skills, and (last but not least!) become a mentor building up great relationships with other Pythonistas.

Back to business ... our new challenge:

In this challenge we're asking you to spice up your life with your very own URL Shortener!

We've all seen sites like that allow you to shorten a URL into something... well... shorter! It's time to you make your own.

There are roughly four parts to this challenge:

  1. Make a small Django/Flask/Bottle app that receives in a URL.

  2. Using the supplied URL, generate a unique URL with the base of It should be generated keeping uniqueness in mind.

  3. Return the shortened URL.

  4. Bonus: track the visits in a second DB table for stats.

It sounds more complex but breaking it down into these steps should help you tackle the problem more effectively.

Good luck and have fun!

Ideas and feedback

If you have ideas for a future challenge or find any issues, open a GH Issue or reach out via Twitter, Slack or Email.

Last but not least: there is no best solution, only learning more and better Python. Good luck!

Become a Python Ninja

At PyBites you get to master Python through Code Challenges:

>>> from pybites import Bob, Julian

Keep Calm and Code in Python!

PyBites Python Tips

Do you want to get 250+ concise and applicable Python tips in an ebook that will cost you less than 10 bucks (future updates included), check it out here.

Get our Python Tips Book

"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H

"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B

"This is now my favourite first Python go-to reference." - Anthony L

"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S

Get the book