How to Build a Python SDK From Scratch

https://hackernoon.imgix.net/images/5wpKgV75aONqkTJlafw2yQmK9yd2-gp83b8z.jpeg

Every developer uses SDKs: pip install stripe, import stripe, done. But almost nobody knows what happens inside that black box. I built a complete Python SDK for the Stripe API from scratch, authentication, request handling, error management, retries, models, and tests. This article walks through every line. By the end, you will understand SDKs so deeply you could build one for any API in the world.

The Import Line I Never Questioned

import stripestripe.api_key = "sk_test_..."charge = stripe.PaymentIntent.create(amount=2000, currency="usd")

I have written this code dozens of times. I never once stopped to ask what stripe actually is. What happens when I call .create()? Where does the HTTP request come from? How does it handle errors? What happens when Stripe's API is slow?

One afternoon, driven by pure curiosity, I decided to find out. I deleted stripe from my project, banned myself from reinstalling it, and started building my own version...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE