Benefits of GitHub - Learning 10+ python packages in half a week!
Published: 2019-12-18 18:03:42

So, you might be asking yourself, open source is beneficial and all but learning *10+ python packages in half a week?* what gives?

It was all thanks to this year's hacktoberfest and all the projects that I got to work on during it. I worked on [zairza-website by zairza-website](https://github.com/zairza-cetb/zairza-website), [pizza-ordering by Aniketh01](https://github.com/Aniketh01/pizza-ordering), [ms by Sacules](https://github.com/Sacules/ms) and [traxss by m4cs](https://github.com/M4cs/traxss). That last one is important, you'll find out why soon.

All that inspired me to work on my own pet projects a lot of which I published to my own [GitHub](https://github.com/TotallyNotChase). Through that I advanced my knowledge with Python, Java, C and ES6.

Ok so, now for the **real deal**. Remember traxss? the project I mentioned above? I contributed a lot of code to it and sort of became a welcome contributor to m4cs. Earlier this week, after a long time of inactivity, I noticed a new repo on their profile - [pixcryption](https://github.com/M4cs/pixcryption)! I got excited seeing that as it seemed interesting to me. But it was using `PIL`, `numpy`, `uuid` and `itertools`. I didn't have experience with any of them beforehand.

But when I saw it had an issue open about implementing AES encryption (something I didn't even know about), I couldn't hold in my curiosity. I read up on it immediately, saw `Pycryptodome` and asked m4cs to assign me to it!

Ofcourse, `Pycrptodome` wouldn't cut it all, all the `keys` and necessary info needed to be stored in tuples of integers (range being from 0 to 255) representing each pixel. And since each key was a `byte_string` some of 15 bytes and some of 16, it wouldn't be an easy task to store them in tuples. And so, I got to reading more and eventually I figured it out. Using `itertools`, I converted the `byte_str` into a **list** and then basically turned the whole list into a **list of tuples of 3 integers** and I filled the empty tuple slots with 0. So a list of 4 integers like this:- `[1, 2, 3, 4]` would convert into = [(1, 2, 3), (4, 0, 0)]. Eventually I got everything sorted out and pixcryption now has AES encryption *along* with base64 encoding to boast!

![](https://thepracticaldev.s3.amazonaws.com/i/9fl0ox9bqcbalrtzawc6.png)

Things I learned from **pixcryption**:-
* PIL (in general)
* `numpy.array()`
* `itertools.product()` and `itertools.zip_longest()`
* AES encryption/decryption
* base64 encoding/decoding

I got in good terms with the creator of pixcryption, m4cs, now. So I got to work on his latest service [jsonsty](https://github.com/M4cs/jsonsty). He asked me to implement data encryption before storage and decryption after retrieval. But this is a flask web app and also uses a REST api that I'll also have to tweak. Unfortunately, I knew neither.

So I got in **reading and testing** again. I first got accustomed to `flask` web apps and how to run it on localhost and how to debug it an what not and then ran through the code. I've always been a believer of the quote `Practical experience is always better than theoretical` and I can definitely say that working hands on with this app *along* with fetching the docs here and there, I got accustomed to flask **way** faster than I would've without an actual working web app. I then had to get familiar with `pymongodb`, which was also fairly straightforward due to to the web app being a live example. After I felt comfortable with the code, I found it easy to implement the `encryption/encode` and `decode/decryption` functions, *which were already in place at pixcryption*,  in the web app.

![](https://thepracticaldev.s3.amazonaws.com/i/z8ersbqp504q3m28iw6d.png)

But here's the final challenge, the front_end of the web app expects a **python dict object** in **json format**. But that is impossible (or atleast tough to implement) given the fact that python represents strings with a *single quote* instead of a *double quote* that `.json` format requires. This made me read in depth into python's `json` library because at first I couldn't even figure out *why* it was returning *clearly json formatted objects* with a single quote. I ended up storing the data as python dict in backend but using `json.dumps()` to get a string for the front_end.

After that, I read up a bit on `flask.jsonify()` and `requests` for handling the REST api and tweaked that to work with the encryption/decryption as well. The api returns the **python dict object** itself upon request. Then either `jsonify()` or `json.dumps()` can be used to represent that into proper/required format.

Later, I was asked to patch up the `unittest` for the api and through that I got to run my first ever unit tests in python!

**SUCCESS!**! The unit tests passed! ![](https://thepracticaldev.s3.amazonaws.com/i/xwakqm6f7cg6y26jq6jq.png)
And The web frontend works like a charm! ![](https://thepracticaldev.s3.amazonaws.com/i/jrqnscdhecnyw6yupvx0.png)

Things I learned from **jsonsty**:-
* flask (in general)
* pymongodb (in general)
* REST API
* json
* unittest

But wait the gifts don't end! By my friends in the open source community I was recommended to check out [liboqs by open-quantum-safe](https://github.com/open-quantum-safe/liboqs) and [awesome-cryptography by sobolevn](https://github.com/sobolevn/awesome-cryptography). These are also 2 phenomenal pieces of open source projects!

And just like that, I learnt ALL THOSE in half a week! And I sincerely believe anyone can do just the same. Whether you use the links I provided here to learn (e.g the ongoing pixcryption, jsonsty) or something else from the endless sea of great open source projects that I'm sure you'll find. Just remember, learning something practically is gonna bring down your time to learn it exponentially!