npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

v8python

v0.1.2

Published

Python 3 interpreter implemented in pure JavaScript, running on V8 (Node.js). Zero dependencies.

Readme

v8python

V8(Node.js)上で動く Python 3 処理系。純粋な JavaScript・依存ゼロで実装した Python インタプリタです。字句解析 → 再帰下降パーサ → JS ジェネレータベースの ツリーウォーク評価器、という構成になっています。

$ ./v8python fib.py
$ ./v8python          # 対話 REPL

インストール

# npm からグローバルインストール
npm install -g v8python
v8python script.py

# あるいは npx で都度実行
npx v8python script.py

使い方

# スクリプトを実行(リポジトリを clone した場合)
./v8python script.py [引数...]

# 対話モード(REPL)
./v8python

# CPython との差分テスト(python3 が必要)
node tests/run_tests.js          # 全件
node tests/run_tests.js dict     # ファイル名に "dict" を含むケースのみ

Node.js 18 以降を想定(BigInt・structuredClone 不使用・ESM)。

対応している機能

  • データ型: 任意精度整数(BigInt)、浮動小数、文字列(コードポイント単位)、 bool、None、list、tuple、dict(挿入順保持)、set / frozenset、range、slice、bytes は非対応
  • 制御構文: if/elif/else、for/while(else 節つき)、break/continue、with、 try/except/else/finally、raise(from つき)、assert、del、global/nonlocal
  • 関数: デフォルト引数、*args / **kwargs、キーワード専用引数、位置専用引数、 クロージャ、nonlocal、デコレータ、ラムダ、再帰
  • クラス: 単一・多重継承(C3 線形化による MRO)、super()、 演算子オーバーロード(__add__ / __radd__ / __eq__ / __lt__ / __getitem__ …)、 propertyclassmethod / staticmethod__iter__ / __next__、 カスタム __hash__ / __eq__isinstance / issubclass
  • ジェネレータ: yieldyield fromsend / throw / close、 ジェネレータ式、return 値(StopIteration.value
  • 内包表記: list / dict / set 内包、ネスト、条件つき、独立スコープ
  • 文字列整形: f-string({x:.2f}{x!r}、ネスト指定 {v:{w}.{p}f}、 自己文書化 {x=})、str.format% 演算子
  • 標準ライブラリ: math / sys / time / random / functools / itertools / json / collections / string / operatortyping / __future__ はスタブ)
  • ファイル import: スクリプトと同じディレクトリの .pyimport 可能

未対応の機能は docs/limitations.md を参照してください。

アーキテクチャ

src/lexer.js     字句解析。インデントを INDENT/DEDENT トークンに変換し、
                 括弧内の暗黙の行継続、f-string の構造解析を行う。
src/parser.js    再帰下降パーサで AST を構築し、続くスコープ解析パスで
                 各関数・ラムダ・内包表記の local / global / nonlocal を確定する。
src/objects.js   オブジェクトモデル。型システム(C3 MRO)、属性アクセス、
                 演算子ディスパッチ、ハッシュ/等価、反復、repr/str を実装。
src/fmt.js       CPython 互換の浮動小数フォーマット。IEEE-754 ビットを BigInt で
                 取り出し、正確な十進スケーリングで偶数丸めを行う。
src/builtins.js  組み込み関数と、str/list/dict/set 等のメソッドテーブル。
src/interp.js    ツリーウォーク評価器。yield を実現するため、すべての評価関数を
                 JS ジェネレータ関数として書いている。
src/stdlib.js    標準ライブラリモジュール群。
src/repl.js      対話 REPL(複数行ブロック入力・式結果の repr 表示)。
src/cli.js       CLI エントリ。ファイル実行・traceback 整形・stdin/stdout/fs 接続。
v8python         実行ランチャ(bash)。src/cli.js を node で起動するだけのラッパ。

設計上の面白い点

  • Python の int を JS の BigInt で表現2 ** 100 のような任意精度演算が そのまま動く。float は通常の JS number。
  • dict は挿入順を保持 — JS の Map をハッシュバケットに使い、値ベースの 等価(11.0True を同一キーとして扱う)を実装。
  • yield を「すべての評価関数を JS ジェネレータにする」ことで実現 — Python の yield はどんな式の途中でも値を外へ送出できる。これを、評価器の evalExpr / execStmt 等を function* にし、yield* のチェーンで値を PyGenerator まで 伝播させることで自然に表現している。JS から Python コードを呼ぶ箇所(dunder の 呼び出しなど)はジェネレータを同期的に駆動する。
  • 浮動小数の repr が CPython と一致0.1 + 0.20.30000000000000004 に なるところまで、IEEE-754 の正確な十進展開と round-half-even で再現している。

テスト

tests/cases/*.py の各ファイルを CPython(python3)と v8python の両方で実行し、 標準出力と例外型を比較しています(136 ケースが完全一致)。新しいテストを書く際は tests/GUIDELINES.md の制約(set の出力順、random の値比較禁止 など)を参照してください。