# Locutus: PHP, Go and Python standard library functions as TypeScript imports

> Locutus is a TypeScript package of roughly 500 reimplemented standard library functions from PHP, Go, Python, Ruby and C. It is a port of behaviour, not of runtime types, and the README is explicit about that boundary.

**locutusjs/locutus** — Bringing stdlibs of other programming languages to TypeScript for fun

- Repository: https://github.com/locutusjs/locutus
- Website: https://locutus.io
- Stars: 3,761 · Forks: 1,082
- Language: TypeScript
- License: NOASSERTION
- Published: 2026-09-23 · Updated: 2026-09-23 · Language: en
- Canonical page: https://hysenlabs.com/projects/locutusjs-locutus

## What Locutus actually ports, and for whom

Locutus is a collection of roughly 500 TypeScript implementations of standard library functions taken from PHP, Go, Python, Ruby, C and other languages, published on npm as locutus. The README frames the origin plainly: most functions started as weekend puzzles, some are genuinely useful, and all of them are a way to study how different languages solve the same problem. That framing matters when you decide whether to depend on it, because it tells you the project's own standard for inclusion is curiosity as much as production need.

The audience is narrower than the function count suggests. If you are porting a PHP script to Node and want sprintf to behave the way it did, or you are reading Go code and want to check a substring the way Go's strings.Contains does, Locutus gives you that as a single import. It is not a translation layer, not a polyfill set and not a compatibility shim for running foreign code. Nothing here executes PHP or Go. You get TypeScript functions that reproduce documented behaviour.

## The scope rule: behaviour without foreign runtime baggage

The README states the design constraint directly: Locutus ports function behaviour, not foreign runtime baggage, and keeps API boundaries JavaScript-native. The consequence is spelled out with examples. Go slices and maps, Python tuples and bytes, Ruby symbols, C structs and pointers, and Perl refs are not recreated in Locutus APIs. A Go date-formatting port should accept a JavaScript Date and return a string, not a custom Go time.Time object.

This is the single most useful thing to understand before adopting the package, and it is also where most disappointment will come from. If your code needs a Python bytes type with its own slicing semantics, Locutus is the wrong tool, because it will hand you a JavaScript value instead. The one documented exception is PHP compatibility: plain JS objects may be treated as associative arrays when locutus.objectsAsArrays is enabled. That flag is a compatibility concession, not a general design principle, and it is the only such exception the README names.

## Installing Locutus and calling your first ported function

The README gives one install command, with no peer dependencies or build steps mentioned:

```bash
npm install locutus
```

Once installed, functions are imported by deep path. The README's first example is the PHP sprintf port, imported from locutus/php/strings/sprintf, and it prints a formatted string:

```typescript
import { sprintf } from 'locutus/php/strings/sprintf'

const effectiveness = 'futile'
console.log(sprintf('Resistance is %s', effectiveness))
// Resistance is futile
```

The second example comes from the Go side and returns a boolean. Note the capital C in the export name, which follows the Go function it mirrors rather than JavaScript naming convention:

```typescript
import { Contains } from 'locutus/golang/strings/Contains'

console.log(Contains('Locutus', 'cut'))
// true
```

That uppercase export is a small but real friction point: lint rules that enforce camelCase imports will flag it, and you will have to alias it at the import site.

## Deep imports versus category index imports in browser bundles

The README treats bundle size as a decision the consumer makes, not something the package solves for you. Its guidance is to prefer per-function deep imports over category index imports in bundle-sensitive browser builds. The good form is the deep path shown earlier; the form to avoid is importing from a category index such as locutus/php/strings/index.

The stated reasons are mechanical. Deep imports pull only the function you asked for and its real dependencies. Category index imports can force bundlers to traverse many unrelated exports in the same namespace, and the README notes this matters most in prebundled UMD or browser artifacts where downstream tree-shaking cannot recover afterwards. The package.json sets sideEffects to false, which supports tree-shaking, but that flag only helps if the import graph is narrow to begin with. If you publish your own browser bundle on top of Locutus, the README says to treat deep imports as the default.

## Runtime targets, polyfills and the Node version floor

Locutus draws a line between the snippets on its function pages and the package runtime. Code shown on function pages, labelled Module JS and Standalone JS, targets baseline widely available with downstream. The package itself requires Node engines.node >= 22, and the published dist output ships as CommonJS in dist/ plus ESM in dist/esm, compiled to ES2022.

The README is direct that Locutus does not inject polyfills into copy-paste snippets by default. If your application targets older browsers, you are expected to transpile the snippet with your own toolchain (TypeScript, Babel, SWC or esbuild are the named examples), add polyfills for APIs missing in your environment, and validate against your own Browserslist target and browser test matrix. This is a reasonable division of labour, but it means a snippet copied from a function page is not a drop-in for a legacy browser target. The Node 22 floor is also worth checking against your CI images before you add the dependency, since it is stricter than many current LTS setups.

## Where Locutus stops being the right choice

The scope rule creates the main failure mode. Any task that depends on a foreign language's data model rather than its function semantics will not be served here. Porting code that passes a Python tuple around, or that relies on Go slice aliasing behaviour, or that uses C pointer arithmetic, means rewriting those parts around JavaScript objects, arrays and numbers. Locutus will not preserve the semantics you were porting, and the README says so rather than leaving it to be discovered.

A second limitation is the project's own framing. The README describes the functions as starting as puzzles, with some genuinely useful and some just fun to write. That is honest, and it should shape your expectations: parity coverage and edge-case handling will vary by function, and the project's versioning policy is pragmatic, with patch as the default bump even for function-level parity fixes. A patch release can therefore change how a function behaves. If you pin loosely and depend on a specific edge case, read the changelog before upgrading rather than assuming semver protects you.

A third boundary is the licence split, covered below, which makes part of the package unsuitable for some distribution models.

## How Locutus differs from a language runtime in JavaScript

The obvious alternative is a runtime that actually executes the other language in JavaScript, such as a PHP-to-JavaScript transpiler or a Python interpreter compiled to WebAssembly. The difference in approach is fundamental. A transpiler or interpreter aims to run your existing foreign source, which means carrying the language's object model, its standard library and often a sizeable runtime. Locutus does the opposite: it reimplements individual standard library functions as native TypeScript, one import at a time, and deliberately refuses to carry the object model.

That trade-off cuts both ways. Locutus is far lighter for a single function and composes naturally with TypeScript types, but it cannot run a foreign program and cannot promise that a ported function behaves identically in every edge case. If your goal is to execute existing PHP or Python code, Locutus is not a candidate at all. If your goal is to have one familiar function available in JavaScript, a full runtime is a large amount of machinery for that.

## Maintenance cadence, licence split and upgrade cost

The last push to the repository was on 2026-05-16, and the most recent release listed is v3.0.36 on the same date, preceded by v3.0.35 on 2026-05-15 and v3.0.34 on 2026-03-30. The repository is not archived. The release cadence visible in that short window is frequent, with two releases a day apart, which is consistent with the pragmatic versioning described in CONTRIBUTING.md: patch is the default bump even for function-level parity fixes. For a consumer this means upgrades are cheap to install but require attention, because a patch can correct behaviour your code was relying on.

Licensing is not uniform. The package.json declares MIT, and the README confirms MIT as the general licence, with one carve-out: src/php/bc/ and src/php/_helpers/_bc.js are LGPL-2.1, derived from PHP's bcmath and Libbcmath. If you only import functions outside those paths, the MIT terms apply. If you depend on the bcmath ports, the LGPL-2.1 terms attach to those files, and how that interacts with your distribution model is a question for your own licence review, not something this article can settle. The README points to LICENSE for details.

## Conclusion

Adopt Locutus when you need one specific foreign stdlib behaviour in a JavaScript or TypeScript codebase and you want it as a plain function rather than a runtime dependency: sprintf for PHP-style formatting, Contains for Go-style substring checks, and similar single-purpose ports. Do not adopt it expecting Python tuples, Go slices, Ruby symbols or C pointers to exist in your code; the README states those object models are deliberately not recreated, so code that depends on them has to be rewritten around JavaScript types. Before committing, open the specific function page on locutus.io to see the copy-paste snippet and its stated target of baseline widely available with downstream, check that your Node version satisfies engines.node >= 22, and read LICENSE to confirm whether the function you want sits under MIT or under the LGPL-2.1 bcmath-derived files in src/php/bc/.

## FAQ

### What is Locutus on npm?

It is a TypeScript package published as locutus containing roughly 500 implementations of standard library functions from PHP, Go, Python, Ruby, C and other languages. Each function is individually importable by a deep path such as locutus/php/strings/sprintf.

### How do I install Locutus and use a single function?

Install it with npm install locutus, then import the function from its deep path, for example import { sprintf } from 'locutus/php/strings/sprintf'. Deep imports are the form the README recommends over category index imports.

### Does Locutus recreate Python tuples or Go slices?

No. The README states that Locutus ports function behaviour, not foreign runtime baggage, and explicitly lists Go slices and maps, Python tuples and bytes, Ruby symbols and C structs and pointers as things it does not recreate. A Go date-formatting port should accept a JavaScript Date and return a string.

### What Node version does Locutus require?

The package runtime targets engines.node >= 22, and the published dist output is ES2022. Function page snippets target baseline widely available with downstream, and Locutus does not inject polyfills into those snippets by default.

### Is Locutus licensed under MIT?

The package is MIT, with one exception: src/php/bc/ and src/php/_helpers/_bc.js are LGPL-2.1, derived from PHP's bcmath and Libbcmath. The README refers to LICENSE for the full details.

## Sources

- [Issues](https://github.com/locutusjs/locutus/issues)
- [locutusjs/locutus on GitHub](https://github.com/locutusjs/locutus)
- [Project website](https://locutus.io)
- [README](https://github.com/locutusjs/locutus/blob/main/README.md)
- [Releases](https://github.com/locutusjs/locutus/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/locutusjs-locutus
