A reflection on designing my first API
Tags: opensource, python, showdev, blogging
Published: 2020-12-07 18:13:06

For the last two months, I have been spending many, _many_ hours working on an open source Python library ([`instascrape`](https://github.com/chris-greening/instascrape)). Despite all this time spent, the library's codebase is still relatively small.

So where were all these many, _many_ hours working spent? 
_Designing an API people actually want to use._

{% tweet 702544348307693568 %}

For every hour I spend coding, I spend like five hours doing work on the library that isn't coding. Despite loving to code more than anything, I love seeing _others_ love to code as much as I do. 

Knowing that the API for a project I designed isn't an absolute dumpster fire is what helps me sleep at night. 

---

# The earliest iteration of instascrape 

![Star Wars intro](https://miro.medium.com/max/2908/0*n6zzxzDrGFPV6Tue.png)

The earliest version of `instascrape` started in Summer 2019. I had just learned Instagram's Developer API was about to dry up and thus the idea for `instascrape` was born. 

I did some research, pip installed `selenium`, figured out how the heck to configure chromedriver, wrote some code, and the result was \*drumroll\*.... 

_terrible_. 

It was clunky, the code was awful, and it was _sloooooowwwwwwwwwww_. Despite this, I was able to get a taste for what was possible and thus the earliest version of what would become `instascrape` was born.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y10f5wbbeo0g3nw1k9is.png)

---

# Fast forward a year later 

Before I wrote a single line of code for the version of `instascrape` that exists today, I knew I had to design it to be as easy to use as possible.

There was only one problem, I had _never_ designed an API before and didn't know where to begin.

So I started hacking away: I wrote some code, I hated it, I did some research, I wrote some more code, I hated it some more, etc... this went on for a week or so until I had an epiphany and knew that I was setting my goals way too high and had to bring myself back down to Earth. 

---

# import this 

```python
import this
```

I am a firm believer in [The Zen of Python](https://www.python.org/dev/peps/pep-0020/) and realized that my API was starting to stray _quite_ far from my beliefs on how Python code should feel. 

I scrapped everything and started once again from scratch; this time reminding myself of The Zen of Python every step of the way.  Anytime something in the API felt even a little nonobvious I immediately took a step back, reevaluated, and fixed it. 

Because of this, the development process has been way slower than I'm used to but it has absolutely paid off. While there is always going to be room for improvement, I am comfortable with knowing that others are using (and judging) this API.  

---

# That's all folks! 

It has been a painstaking process and there is nothing worse than looking at the code you've written and realizing it has to be entirely rewritten from scratch... but that's life! 

Being able to recognize something isn't working and accepting constructive criticism in stride is a skill that I've been learning the hard way the last two months and it has been beyond fulfilling and enlightening in all aspects of my life. 

It's taught me to be deliberate with design choices, move slowly and carefully, and to view my code from the shoes of the average user that has never seen my code before. 

![That's all folks!](https://static.wikia.nocookie.net/warner-bros-entertainment/images/d/d9/That%27s_all_Folks_tagline.jpg/revision/latest/scale-to-width-down/340?cb=20190918210403)

---

# Afterword
Check out the official [instascrape website](https://chris-greening.github.io/instascrape/) or the official repo at 
{% github chris-greening/instascrape %}