Python modules in TypeScript
TypeScript implementations of 56 Python standard library functions across 4 modules. Each function is individually importable and tree-shakeable.
difflib math- acos
- acosh
- asin
- asinh
- atan
- atan2
- atanh
- ceil
- comb
- copysign
- cos
- cosh
- degrees
- dist
- exp
- expm1
- fabs
- factorial
- floor
- fsum
- gcd
- hypot
- isclose
- isfinite
- isinf
- isnan
- isqrt
- lcm
- log
- log10
- log2
- pow
- prod
- radians
- sin
- sinh
- sqrt
- tan
- tanh
- trunc
- ascii_letters
- ascii_lowercase
- ascii_uppercase
- capwords
- digits
- hexdigits
- octdigits
- printable
- punctuation
- whitespace
Help us add more
Got a rainy Sunday afternoon and a taste for a porting puzzle?
- Get inspiration from the Python 3 standard library string page.
- Click "New file" in the appropriate folder on GitHub. This will fork the project to your account, directly add the file to it, and send a Pull Request to us.
We will then review it. If it's useful to the project and in line with our contributing guidelines your work will become part of Locutus and you'll be automatically credited in the authors section accordingly.
Upstream Surface Inventory 56/444 shipped · 181 next 13%
Locutus tracks 25 upstream namespaces for Python and sorts them into what is already shipped, what we still want, what we intentionally keep, and what still needs a decision.
This inventory now targets a broad official core/stdlib slice first, using runtime discovery where possible, rather than the full Python object model or third-party ecosystem.
Complete
In progress
Shipped (40)
Next
Python math helpers map cleanly to JS numbers and arrays.
cbrterferfcexp2fmodfrexpgammaldexplgammalog1pmodfnextafterpermremaindersumprodulp
Shipped (2)
Next
Sequence-diff helpers are high-value portability targets.
context_diffrestoreunified_diff
Explicit non-goals (1)
-
diff_bytesByte-oriented diffing does not fit Locutus' current plain-value model.
Next
Top-level regex helpers are high-value portability targets.
escapefullmatchmatchsearchsplit
Explicit non-goals (4)
operator
Next
First-class operator helpers are strong plain-value portability targets.
absaddand_concatcontainscountOfeqfloordivgegetitemgtindexindexOfinvinvertis_is_notlelshiftltmatmulmodmulnenegnot_or_pospowrshiftsubtruedivtruthxor
Explicit non-goals (21)
-
attrgetterGetter factories return callable objects rather than plain values. -
callIndirect call wrappers add little value beyond direct JS invocation. -
delitemContainer mutation is outside Locutus' value-only model. -
iaddIn-place operator wrappers imply mutation semantics. -
iandIn-place operator wrappers imply mutation semantics. -
iconcatIn-place operator wrappers imply mutation semantics. -
ifloordivIn-place operator wrappers imply mutation semantics. -
ilshiftIn-place operator wrappers imply mutation semantics. -
imatmulIn-place operator wrappers imply mutation semantics. -
imodIn-place operator wrappers imply mutation semantics. -
imulIn-place operator wrappers imply mutation semantics. -
iorIn-place operator wrappers imply mutation semantics. -
ipowIn-place operator wrappers imply mutation semantics. -
irshiftIn-place operator wrappers imply mutation semantics. -
isubIn-place operator wrappers imply mutation semantics. -
itemgetterGetter factories return callable objects rather than plain values. -
itruedivIn-place operator wrappers imply mutation semantics. -
ixorIn-place operator wrappers imply mutation semantics. -
length_hintSize-hint probing adds little value beyond direct JS length checks. -
methodcallerMethod-caller factories return callable objects rather than plain values. -
setitemContainer mutation is outside Locutus' value-only model.
builtins
Next
Scalar absolute-value helpers are strong plain-value targets.
abs
Aggregate predicate helpers have a clean plain-value contract.
allany
ASCII-safe string representation is a useful plain-value helper.
ascii
Integer base conversion has a clean plain-value contract.
binhexoct
Boolean coercion remains a useful plain-value portability target.
bool
Callable predicates have a clean plain-value contract.
callable
Codepoint-to-string conversion is a strong portability target.
chr
Dictionary construction still has a clean plain-value contract.
dict
Quotient-remainder helpers have a clean plain-value contract.
divmod
Indexed sequence pairing can be represented as plain arrays.
enumerate
Predicate-based filtering remains a strong plain-value target.
filter
Numeric coercion has a clean plain-value contract.
float
String formatting is a strong plain-value portability target.
format
Integer coercion is a strong plain-value portability target.
int
Size helpers are strong plain-value portability targets.
len
Sequence materialization has a clean plain-value contract.
listtuple
Mapping over iterables can be represented as plain arrays.
map
Aggregate scalar helpers have a clean plain-value contract.
maxmin
String-to-codepoint conversion is a strong portability target.
ord
Scalar exponentiation has a clean plain-value contract.
pow
Numeric range generation can be represented as plain arrays.
range
Representation helpers are useful plain-value string targets.
repr
Reversal can be represented as a plain array result.
reversed
Scalar rounding remains a strong portability target.
round
Sequence sorting has a clean plain-value contract.
sorted
String coercion remains a strong plain-value portability target.
str
Aggregation helpers are strong plain-value portability targets.
sum
Sequence zipping can be represented as plain arrays.
zip
Explicit non-goals (35)
-
aiterPython builtins mix pure helpers with runtime introspection, evaluation, I/O, and rich container types too broadly for one direct Locutus wishlist. -
anextPython builtins mix pure helpers with runtime introspection, evaluation, I/O, and rich container types too broadly for one direct Locutus wishlist. -
breakpointDebugger entry mutates runtime execution state. -
bytearrayMutable byte buffers do not fit Locutus' current plain-value model. -
bytesByte strings do not fit Locutus' current plain-value model. -
classmethodDescriptor factories are not plain-value targets. -
compileDynamic code compilation is security-sensitive and not a good Locutus target. -
complexComplex numbers do not fit Locutus' current plain-value model. -
delattrAttribute mutation is outside Locutus' value-only model. -
dirRuntime introspection depends on object model details outside Locutus' scope. -
evalDynamic code evaluation is security-sensitive and out of scope. -
execDynamic code execution is security-sensitive and out of scope. -
frozensetSet semantics do not map cleanly onto Locutus' plain-value model. -
getattrGeneric attribute lookup depends on host object semantics. -
globalsRuntime namespace introspection is outside Locutus' portability scope. -
hasattrGeneric attribute introspection depends on host object semantics. -
hashObject-hash identity does not map cleanly to JS plain values. -
idObject identity addresses are not a stable portability target. -
inputInteractive stdin reads depend on host I/O. -
isinstancePython class introspection does not fit Locutus' plain-value model. -
issubclassPython class introspection does not fit Locutus' plain-value model. -
iterIterator objects are not direct plain-value results. -
localsStack-frame introspection is outside Locutus' portability scope. -
memoryviewBuffer-view semantics do not fit Locutus' current plain-value model. -
nextIterator advancement APIs do not fit Locutus' plain-value model. -
objectGeneric object construction has no meaningful plain-value portability target. -
printOutput emission is outside Locutus' value-only model. -
propertyDescriptor factories are not plain-value targets. -
setSet semantics do not map cleanly onto Locutus' plain-value model. -
setattrAttribute mutation is outside Locutus' value-only model. -
sliceSlice objects are not direct plain-value results. -
staticmethodDescriptor factories are not plain-value targets. -
superMethod-resolution proxies do not fit Locutus' plain-value model. -
typePython class introspection does not fit Locutus' plain-value model. -
varsRuntime namespace introspection is outside Locutus' portability scope.
calendar
Next
Calendar helpers mostly return scalars, strings, or plain arrays with a useful portability contract.
calendardifferent_localefirstweekdayformatformatstringisleapleapdaysmainmonthmonthcalendarmonthrangeprcalprmonthprweektimegmweekweekdayweekheader
Explicit non-goals (1)
-
setfirstweekdayGlobal calendar configuration mutates ambient runtime state.
statistics
Next
Aggregate statistics helpers are strong plain-value portability targets.
correlationcovariancefmeangeometric_meanharmonic_meanlinear_regressionmeanmedianmedian_groupedmedian_highmedian_lowmodemultimodepstdevpvariancequantilesstdevvariance
itertools
Next
Accumulation over plain iterables can be represented as arrays of intermediate results.
accumulate
Fixed-size chunking is a strong plain-value portability target.
batched
Sequence concatenation maps naturally onto arrays.
chain
Finite combinatorics helpers can be represented as arrays of tuples.
combinationscombinations_with_replacementpermutations
Mask-based filtering has a clean plain-value contract.
compress
Predicate-based slicing has a clean plain-value contract.
dropwhiletakewhile
Predicate-based filtering has a clean plain-value contract.
filterfalse
Iterator slicing maps naturally onto array slicing semantics.
islice
Adjacent-pair grouping can be represented as arrays of tuples.
pairwise
Cartesian products can be represented as arrays of tuples.
product
Spread-argument mapping still has a clean plain-value contract.
starmap
Sequence zipping has a strong plain-value contract.
zip_longest
Explicit non-goals (5)
-
countMany itertools helpers are lazy or stateful iterator factories rather than direct plain values. -
cycleMany itertools helpers are lazy or stateful iterator factories rather than direct plain values. -
groupbyMany itertools helpers are lazy or stateful iterator factories rather than direct plain values. -
repeatMany itertools helpers are lazy or stateful iterator factories rather than direct plain values. -
teeMany itertools helpers are lazy or stateful iterator factories rather than direct plain values.
unicodedata
Next
Unicode classification and normalization helpers are strong plain-value portability targets.
bidirectionalcategorycombiningdecimaldecompositiondigiteast_asian_widthis_normalizedlookupmirrorednamenormalizenumeric
urllib.parse
Next
Query parsing into plain objects and arrays has a clean portability contract.
parse_qs
Query parsing into key-value pairs has a clean portability contract.
parse_qsl
URL escaping helpers are strong plain-value portability targets.
quotequote_plus
URL unescaping helpers are strong plain-value portability targets.
unquoteunquote_plus
Query encoding has a clean plain-value portability contract.
urlencode
URL joining has a clean plain-value portability contract.
urljoin
Explicit non-goals (20)
-
clear_cacheParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
quote_from_bytesParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splitattrParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splithostParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splitnportParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splitpasswdParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splitportParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splitqueryParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splittagParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splittypeParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splituserParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
splitvalueParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
to_bytesParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
unquote_to_bytesParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
unwrapParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
urldefragParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
urlparseParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
urlsplitParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
urlunparseParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract. -
urlunsplitParts of urllib.parse return structured parse-result objects rather than one stable plain-value contract.
textwrap
Next
Text formatting and wrapping helpers are strong plain-value portability targets.
dedentfillindentshortenwrap
bisect
Next
Binary-search helpers are strong plain-value portability targets.
bisectbisect_leftbisect_right
Explicit non-goals (3)
-
insortIn-place list insertion mutates caller-owned state. -
insort_leftIn-place list insertion mutates caller-owned state. -
insort_rightIn-place list insertion mutates caller-owned state.
heapq
Next
Heap-based selection helpers still have a useful plain-value contract when modeled as array-returning utilities.
mergenlargestnsmallest
Explicit non-goals (5)
-
heapifyIn-place heap mutation is outside Locutus' value-only model. -
heappopIn-place heap mutation is outside Locutus' value-only model. -
heappushIn-place heap mutation is outside Locutus' value-only model. -
heappushpopIn-place heap mutation is outside Locutus' value-only model. -
heapreplaceIn-place heap mutation is outside Locutus' value-only model.
json
Next
JSON encode/decode helpers are strong plain-value portability targets.
detect_encodingdumpsloads
html
Next
HTML escape and unescape helpers are strong plain-value portability targets.
escapeunescape
csv
Next
Dialect enumeration has a clean plain-value contract.
list_dialects
Explicit non-goals (9)
-
excelReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
excel_tabReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
field_size_limitReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
get_dialectReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
readerReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
register_dialectReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
unix_dialectReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
unregister_dialectReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default. -
writerReader and writer objects are stream-oriented and do not fit one stable plain-value contract by default.
functools
Next
Left-folding over plain iterables is a strong portability target.
reduce
Explicit non-goals (11)
-
cacheMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
cached_propertyMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
cmp_to_keyMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
lru_cacheMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
partialMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
partialmethodMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
singledispatchMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
singledispatchmethodMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
total_orderingMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
update_wrapperMost functools exports are decorators, wrappers, or callable factories rather than plain values. -
wrapsMost functools exports are decorators, wrappers, or callable factories rather than plain values.