pythonlib
v2.0.4
Published
Python standard library for TypeScript - itertools, functools, collections, datetime, re, and more. Zero dependencies. Full TypeScript support.
Maintainers
Readme
pythonlib
Python's Beloved Standard Library — Now in TypeScript
Miss itertools.combinations? Love collections.Counter? Wish you had functools.lru_cache in
JavaScript?
pythonlib brings Python's most powerful utilities to TypeScript — zero dependencies, full type safety, tree-shakeable.
Install
npm install pythonlibWhy pythonlib?
| What You Get | Why It Matters | | --------------------------- | ------------------------------------------------- | | Zero dependencies | No supply chain bloat, minimal attack surface | | Full TypeScript support | Generics, type inference, autocomplete everywhere | | Tree-shakeable | Bundle only what you use | | camelCase API | Feels native in TypeScript | | Works everywhere | Browsers, Node.js, Deno, Bun, Workers |
Quick Examples
itertools — Combinatorics Made Easy
import { combinations, permutations, product } from "pythonlib/itertools"
// All 2-element combinations
[...combinations([1, 2, 3], 2)]
// → [[1, 2], [1, 3], [2, 3]]
// Cartesian product
[...product(["a", "b"], [1, 2])]
// → [["a", 1], ["a", 2], ["b", 1], ["b", 2]]collections — Data Structures That Just Work
import { Counter, defaultdict, deque } from "pythonlib/collections"
// Count anything
const votes = new Counter(["alice", "bob", "alice", "alice"])
votes.mostCommon(1) // → [["alice", 3]]
// No more "undefined" checks
const graph = defaultdict(() => [])
graph.get("node1").push("node2") // Just works!
// Double-ended queue with O(1) operations
const dq = new deque([1, 2, 3])
dq.appendLeft(0) // [0, 1, 2, 3]
dq.pop() // [0, 1, 2]functools — Functional Programming Utilities
import { lruCache, partial, reduce } from "pythonlib/functools"
// Memoization with one line
const fib = lruCache((n: number): number => (n <= 1 ? n : fib(n - 1) + fib(n - 2)))
fib(100) // Instant, even for large values
// Partial application
const greet = (greeting: string, name: string) => `${greeting}, ${name}!`
const sayHello = partial(greet, "Hello")
sayHello("World") // → "Hello, World!"Builtins — Python's Greatest Hits
import { range, enumerate, zip, sorted, reversed } from "pythonlib"
// Python-style range
for (const i of range(5)) {
} // 0, 1, 2, 3, 4
for (const i of range(1, 10, 2)) {
} // 1, 3, 5, 7, 9
// Enumerate with index
for (const [i, item] of enumerate(["a", "b", "c"])) {
console.log(i, item) // 0 "a", 1 "b", 2 "c"
}
// Zip multiple iterables
;[...zip([1, 2, 3], ["a", "b", "c"])]
// → [[1, "a"], [2, "b"], [3, "c"]]Available Modules
| Module | Highlights | Docs |
| ----------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------ |
| pythonlib | range, enumerate, zip, sorted, len, min, max | → |
| pythonlib/itertools | chain, combinations, permutations, product, cycle | → |
| pythonlib/functools | lruCache, partial, reduce, pipe, compose | → |
| pythonlib/collections | Counter, defaultdict, deque, OrderedDict | → |
| pythonlib/math | sqrt, floor, ceil, factorial, gcd, pi | → |
| pythonlib/random | randInt, choice, shuffle, sample, random | → |
| pythonlib/datetime | datetime, date, time, timedelta | → |
| pythonlib/re | search, match, findAll, sub, compile | → |
| pythonlib/json | loads, dumps with Python semantics | → |
| pythonlib/string | Template, capWords, ascii_lowercase | → |
| pythonlib/os | path.join, environ, getcwd | → |
| pythonlib/pathlib | Path class for filesystem operations | → |
| pythonlib/glob | File pattern matching | → |
| pythonlib/hashlib | md5, sha256, sha512 hashing | → |
| pythonlib/base64 | Base64 encoding/decoding | → |
| pythonlib/uuid | UUID generation | → |
Runtime Support
Works everywhere JavaScript runs:
- Node.js (v22, v24)
- Bun
- Deno
- Browsers (Chrome, Firefox, Safari)
- Edge (Cloudflare Workers, Vercel, AWS Lambda)
Documentation
| Resource | Description | | ---------------------------------------------------------------------------- | ------------------------------------------ | | Homepage | Project overview and quick start | | Runtime Guide | Detailed usage guide | | API Reference | Complete API documentation for all modules |
Related
- python2ts — Transpile Python to TypeScript automatically
- GitHub — Source code, issues, contributions welcome
License
MIT © Sebastian Software GmbH
