DEV Community

Sattyam Jain
Sattyam Jain

Posted on

I Built a Python Library with 90+ Data Structures, Algorithms & Design Patterns

The Interview Prep Problem Every Python Dev Knows

You're prepping for a technical interview. You open LeetCode. You Google "binary search tree Python." You find:

  1. A Medium article from 2019 with broken code
  2. A GeeksforGeeks page with a Java implementation and a note saying "Python version coming soon" (it's been three years)
  3. A YouTube video that's 47 minutes long and spends 30 minutes on theory before writing a single line of code
  4. A GitHub repo with implementations but no tests, no docs, and the last commit was in 2021

Sound familiar?

Here's the thing. If you're a Python developer, you shouldn't have to mentally translate C++ pointer arithmetic or Java generics just to understand a data structure. You shouldn't have to cobble together implementations from five different blog posts. And you definitely shouldn't have to wonder whether the code you're studying actually works.

That's why I built pyPantry -- a single Python library with 90+ implementations of data structures, algorithms, and design patterns. Every implementation is tested. Every one is installable via pip. Every one is written in idiomatic Python.

pip install python-Pantry
Enter fullscreen mode Exit fullscreen mode

That's it. Now you have a reference library for nearly every foundational CS concept, written in the language you actually use.


What's in the Box

pyPantry is organized into three categories: data structures, algorithms, and design patterns. Here's the full inventory.

Data Structures (30+)

Graphs

  • PyGraph -- adjacency list graph
  • PyLinkedGraph -- linked representation

Heaps

  • PyMaxHeap -- max binary heap
  • PyMinHeap -- min binary heap

Linked Lists

  • Standard linked list
  • Doubly linked list
  • Circular linked list
  • Doubly circular linked list
  • Header linked list
  • Skip list

Queues

  • Standard queue
  • Circular queue
  • Double-ended queue (Deque)
  • Priority queue

Stacks

  • Array-based stack
  • Linked stack

Trees

  • Binary tree
  • Binary search tree
  • AVL tree (self-balancing)
  • B-tree
  • Generic tree

Tries

  • Standard trie implementation

Algorithms (27+)

Searching (9 algorithms)

Algorithm Best For
Binary Search Sorted arrays, O(log n)
Linear Search Unsorted data, small arrays
Jump Search Sorted arrays, block-based
Fibonacci Search Sorted arrays, division-free
Exponential Search Unbounded/infinite arrays
Ternary Search Unimodal functions
Interpolation Search Uniformly distributed data
Meta Binary Search Bit-manipulation approach
Sentinel Linear Search Optimized linear scan

Sorting (18 algorithms)

From the fundamentals to the exotic:

  • Comparison-based: Bubble, Selection, Quick, Heap, Shell, Cocktail, Gnome, Odd-Even, Bitonic, Pancake, Strand, Tim
  • Non-comparison: Counting, Radix, Bucket
  • Novelty: Bogo (yes, really), Sleep, Bingo

Every sorting algorithm includes the standard interface so you can swap them interchangeably and compare performance.

Design Patterns (37+)

This is where pyPantry goes beyond most DSA libraries. Full implementations of Gang of Four patterns and more, all in Python.

Creational (6)

  • Abstract Factory, Builder, Factory Method, Object Pool, Prototype, Singleton

Structural (8)

  • Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Private Class Data, Proxy

Behavioral (13)

  • Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Null Object, Observer, Specification, State, Strategy, Template, Visitor

Architectural (5)

  • Event-Driven, Microservices, MVC, MVVM, SOA

Concurrency (5)

  • Active Object, Half-Sync/Half-Async, Leader-Follower, Reactor, Thread Pool

Show Me the Code

Let's walk through a few examples to show how pyPantry works in practice.

Example 1: Stack Operations

from pyPantry.DS.Stack.PyStack import PyStack

stack = PyStack()
stack.push(10)
stack.push(20)
stack.push(30)

print(stack.pop())   # 30
print(stack.peek())  # 20
print(stack.size())  # 2
Enter fullscreen mode Exit fullscreen mode

Clean. Pythonic. No boilerplate.

Example 2: Binary Search Tree

from pyPantry.DS.Tree.PyBinarySearchTree import PyBinarySearchTree

bst = PyBinarySearchTree()
for val in [50, 30, 70, 20, 40, 60, 80]:
    bst.insert(val)

# In-order traversal gives sorted output
print(bst.inorder())   # [20, 30, 40, 50, 60, 70, 80]

# Search
print(bst.search(40))  # True
print(bst.search(99))  # False
Enter fullscreen mode Exit fullscreen mode

Example 3: Sorting Algorithm Comparison

from pyPantry.Algorithm.Sorting.PyQuickSort import PyQuickSort
from pyPantry.Algorithm.Sorting.PyHeapSort import PyHeapSort
from pyPantry.Algorithm.Sorting.PyTimSort import PyTimSort

data = [38, 27, 43, 3, 9, 82, 10]

quick = PyQuickSort()
heap = PyHeapSort()
tim = PyTimSort()

print(quick.sort(data.copy()))  # [3, 9, 10, 27, 38, 43, 82]
print(heap.sort(data.copy()))   # [3, 9, 10, 27, 38, 43, 82]
print(tim.sort(data.copy()))    # [3, 9, 10, 27, 38, 43, 82]
Enter fullscreen mode Exit fullscreen mode

Same interface, different algorithms. Swap them out to understand the tradeoffs. Profile them to see real performance differences.

Example 4: Observer Pattern

from pyPantry.DesignPattern.Behavioral.PyObserver import PySubject, PyObserver

class PriceAlert(PyObserver):
    def update(self, subject):
        print(f"Price changed to: {subject.state}")

stock = PySubject()
alert = PriceAlert()
stock.attach(alert)

stock.state = 142.50  # Triggers: "Price changed to: 142.50"
stock.state = 138.75  # Triggers: "Price changed to: 138.75"
Enter fullscreen mode Exit fullscreen mode

Design patterns are hard to learn from UML diagrams. They're easy to learn from running code.


How pyPantry Compares

Let's be honest about the landscape.

Feature pyPantry LeetCode/HackerRank Random GitHub repos Textbooks
Language Python only Multi-language Varies Usually Java/C++
Installable pip install No Usually not No
Tested Yes, full test suite N/A Rarely N/A
Design patterns 37+ No Sometimes Some
Consistent API Yes N/A No N/A
Maintained Active Yes Usually no Static
Free MIT license Freemium Yes $40-80

pyPantry isn't a replacement for practicing problems on LeetCode. It's the reference library you keep open in the other tab. When you need to understand how an AVL tree rotation works, you don't want a 500-word explanation -- you want to read 30 lines of Python and step through it with a debugger.


Who Is This For

Interview preppers. You're grinding LeetCode and you need a reliable Python reference for every data structure and algorithm. pyPantry is your cheat sheet that actually runs.

CS students. You're taking Data Structures & Algorithms and your textbook uses Java. pyPantry gives you the same concepts in Python, with tests you can run to verify your understanding.

Working developers. You need to implement a priority queue or a trie at work, and you want a clean reference implementation to start from. Copy what you need, adapt it, ship it.

Teachers and mentors. You're teaching DSA and you need working Python examples. pyPantry gives you tested implementations for every major concept.


Installation and Quick Start

Install

pip install python-Pantry
Enter fullscreen mode Exit fullscreen mode

Import What You Need

# Data structures
from pyPantry.DS.Tree.PyAVLTree import PyAVLTree
from pyPantry.DS.LinkedList.PyDoublyLinkedList import PyDoublyLinkedList
from pyPantry.DS.Queue.PyPriorityQueue import PyPriorityQueue

# Algorithms
from pyPantry.Algorithm.Searching.PyBinarySearch import PyBinarySearch
from pyPantry.Algorithm.Sorting.PyMergeSort import PyMergeSort

# Design patterns
from pyPantry.DesignPattern.Creational.PySingleton import PySingleton
from pyPantry.DesignPattern.Structural.PyAdapter import PyAdapter
Enter fullscreen mode Exit fullscreen mode

Project Structure

pyPantry/
  DS/             # Data structures
    Graph/
    Heap/
    LinkedList/
    Queue/
    Stack/
    Tree/
    Trie/
  Algorithm/      # Algorithms
    Searching/
    Sorting/
  DesignPattern/  # Design patterns
    Architectural/
    Behavioral/
    Concurrency/
    Creational/
    Structural/
Enter fullscreen mode Exit fullscreen mode

Everything is organized exactly where you'd expect it. No hunting through nested directories or deciphering clever naming conventions.


The Story Behind It

I built pyPantry because I was frustrated. Every time I needed a quick reference for a data structure in Python, I'd spend 20 minutes googling, evaluating whether the code I found was correct, and then adapting it to my needs. Multiply that by every data structure, algorithm, and design pattern in a CS curriculum, and you're looking at hours of wasted time.

So I sat down and built the library I wished existed. Every implementation follows the same conventions. Every implementation has tests. Every implementation is pip-installable.

Is it comprehensive? 90+ implementations across three categories. I think so.

Is it perfect? No. That's where you come in.


Get Involved

  • Star the repo: github.com/sattyamjjain/pyPantry
  • Install it: pip install python-Pantry
  • Report issues: Found a bug? Open an issue.
  • Contribute: Want to add an algorithm or pattern? PRs are welcome. Check the contributing guide in the repo.
  • Share it: Know someone prepping for interviews? Send them this post.

The goal is simple: every foundational CS concept, implemented in clean Python, tested, and a pip install away. Help me get there.


What data structures or algorithms do you wish had better Python implementations? Drop a comment -- I might add it to pyPantry next.

Top comments (0)