Understanding Python SDKs & Libraries — And How I Built My Own Stripe SDK From Scratch
Software development becomes powerful when we stop writing everything from zero and start reusing high-quality code. That’s exactly where…

Understanding Python SDKs & Libraries — And How I Built My Own Stripe SDK From Scratch
Software development becomes powerful when we stop writing everything from zero and start reusing high-quality code. That’s exactly where libraries and SDKs come in.
In this article, I’ll explain:
- What libraries are
- What SDKs are
- How to import and use them in Python
- How to understand any library
- And finally — a full walkthrough of the Stripe SDK I built using Python, with an example file (
test.py) that uses my custom SDK.
Let’s go step by step. Simple language. Real-world examples. No unnecessary jargon. Ready? Let’s begin.
What Are Python Libraries?
A library in Python is simply a collection of reusable code that helps you do things faster.
Example:
- Want to make HTTP requests? → Use the
requestslibrary - Want to work with JSON? → Use
json - Want to build a web server? → Use
Flask
Libraries save your time by providing already-tested code. Instead of writing 50 lines to perform an API call, you just write:
import requests
response = requests.get("https://api.example.com")
That’s the power of libraries.
What Is an SDK?
SDK = Software Development Kit
Think of an SDK as a specialized toolbox created for a particular service.
Examples:
- Stripe SDK → For payments
- AWS SDK → For cloud automation
- Twilio SDK → For sending messages/calls
An SDK usually provides:
- Functions
- Classes
- Helpers
- Error handling
- Configuration
All designed so developers can interact easily with an external service.
In simple words:
Every SDK is a library, but not every library is an SDK. SDK = Library designed for one specific platform/service.
How Do We Import Libraries in Python?How to Get the Most Out of a Python Library
Python allows imports in three main ways:
- Import the full library
import requests
- Import a specific function
from math import sqrt
- Import with an alias
import numpy as np
Imports help you use code written by someone else — or even by yourself, if it’s in your own SDK.
How to Get the Most Out of a Python Library
Whenever you’re using a library, follow these steps:
Step 1 — Understand its Purpose
Why does this library exist?
Step 2 — Read Problem/Solution Examples
Most docs explain usage with simple code.
Step 3 — Look for Common Patterns
Almost every API library uses:
- GET
- POST
- PUT
- DELETE
SDKs simply wrap them in easy-to-use functions.
Step 4 — Use Error Handling
Always expect:
- invalid API keys
- network failures
- invalid input
Step 5 — Explore the Source Code
Best way to learn? Read how the SDK is written internally.
And that’s exactly what we did next.
Building My Own Python SDK
(Example: SDK for Stripe Payments)
I built a small Python SDK that interacts with Stripe API.
Why Build an SDK for Stripe Payments?
When doing payment integration, developers often repeat the same things:
- Create Product
- Create Price
- Create Checkout Session
- Manage API Keys
- Handle errors
Instead of writing raw requests every time, we built a small SDK that wraps these functions into clean Python methods.
This helps you:
- Understand how professional SDKs are designed
- Make cleaner code
- Handle Stripe operations with simple function calls
Stripe Payment SDK — The Code We Built
Your SDK structure:
stripe_sdk/
__init__.py
stripe_client.py
pyproject.toml
test.py
Inside stripe_client.py, we added:
- Initialize with API Key
- Create Product
- Create Price
- Create Checkout Session
Each method internally uses Python’s requests library.
Here’s the simplified logic:
- Create Product
class StripeClient:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://api.stripe.com/v1"
- Create Product:
def create_product(self, name):
url = f"{self.base_url}/products"
return requests.post(url, headers=self.headers(), data={"name": name}).json()
- Create Price:
def create_price(self, product_id, amount, currency="usd"):
url = f"{self.base_url}/prices"
data = {
"unit_amount": amount,
"currency": currency,
"product": product_id
}
return requests.post(url, headers=self.headers(), data=data).json()
- Create Checkout Session:
def create_checkout_session(self, price_id):
url = f"{self.base_url}/checkout/sessions"
data = {
"mode": "payment",
"success_url": "http://localhost:4242/success",
"cancel_url": "http://localhost:4242/cancel",
"line_items[0][price]": price_id,
"line_items[0][quantity]": 1
}
return requests.post(url, headers=self.headers(), data=data).json()
Clean. Simple. Reusable.
test.py — Using the Stripe SDK We Created
Here is how easy it becomes to use your SDK:
from stripe_sdk.stripe_client import StripeClient
stripe_client = StripeClient(api_key="your_secret_key")
# 1. Create a Product
product = stripe_client.create_product("Devam Coffee")
print("Product:", product)
# 2. Create a Price
price = stripe_client.create_price(product["id"], 120)
print("Price:", price)
# 3. Create Checkout Session
session = stripe_client.create_checkout_session(price["id"])
print("Checkout Session:", session)
That’s it.
No need to manually write long CURL commands No need to use Stripe CLI No need to repeat the same API request code
Just call your methods.
🎉 Why This SDK Is Useful
You learned how to:
· Build your own Python package
· Use requests to call APIs
· Organize code into classes
· Wrap real-world payment APIs
· Build something that feels like a real Stripe SDK
This is an excellent project for:
- Portfolio
- Resume
- Internship interviews
- DevOps/Backend understanding
It shows you know:
- HTTP calls
- Authentication
- Python packaging
- API design
- Error handling
- Clean code practices
🔚 Final Thoughts
Building your own SDK gives you a completely different level of understanding compared to simply using someone else’s library.
You now know:
- What libraries and SDKs are
- How imports work
- How Stripe APIs function internally
- How to wrap APIs into clean reusable functions
- How to write your own SDK like a professional engineer
If you’d like, I can also help you:
- Add logging
- Add error handling
- Add retry logic
- Publish this SDK on PyPI
- Add docs (README.md)
- Create a proper folder structure
Just tell me.
Final Take — You Just Built Your Own Stripe SDK. What’s Next?
If you’ve reached this point, congratulations — you didn’t just learn how to use APIs… you learned how to design a real SDK like a backend engineer.
Most developers only know how to consume SDKs. Very few take the step of actually building one.
And now you’re one of them. 🚀
This tiny project may feel simple, but it teaches the foundations behind every major tech product — from Stripe to AWS to Google Cloud. You now understand how these tools are structured, how they wrap APIs, and how developers interact with them.
So don’t stop here.
👉 Try adding authentication helpers 👉 Build more services inside your SDK 👉 Publish it to PyPI 👉 Or convert this into a portfolio project that stands out
Your journey into building developer tools has just started — and trust me, this is the kind of project interviewers remember.
If you want help extending this SDK or turning it into a full article series, just message me. Let’s build something even cooler next. 🚀
메타데이터
- post_id
- 12e8ea0a8f0d
- slug
- understanding-python-sdks-libraries-and-how-i-built-my-own-stripe-sdk-from-scratch-12e8ea0a8f0d
- url
- https://medium.com/@devamkumar/understanding-python-sdks-libraries-and-how-i-built-my-own-stripe-sdk-from-scratch-12e8ea0a8f0d
- canonical_url
- https://medium.com/@devamkumar/understanding-python-sdks-libraries-and-how-i-built-my-own-stripe-sdk-from-scratch-12e8ea0a8f0d
- author_url
- https://medium.com/@devamkumar
- status
- ok
- fetched_at
- 2026-06-27 18:20:27