Code Challenge 61 – Build a URL Shortener

By on 21 February 2019

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 bit.ly 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 pybit.es. 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:

  • Subscribe to our blog (sidebar) to periodically get new PyBites Code Challenges (PCCs) and updates in your inbox.

  • Apart from this blog code challenge we have a growing collection which you can check out on our platform.

  • Prefer coding bite-sized Python exercises, using effective Test-Driven Learning, and in the comfort of your browser? Try our growing collection of Bites of Py on our platform.

  • Want to do the #100DaysOfCode but not sure what to work on? Take our course and/or start logging your 100 Days progress using our Progress Grid Feature on our platform (you can also use the Grid to do 100 Bite exercises in 100 days, earning a die hard PyBites Ninja Certificate!)


>>> from pybites import Bob, Julian

Keep Calm and Code in Python!

Want a career as a Python Developer but not sure where to start?