New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pyscript-lang

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyscript-lang

🐍 Python-like syntax that transpiles to JavaScript and runs on Node.js | Sintaxe estilo Python que transpila para JavaScript e roda no Node.js

latest
npmnpm
Version
3.0.0
Version published
Maintainers
1
Created
Source

🐍 PyScript

English | Português

npm version License: MIT Node.js

Write Python, Execute JavaScript

English

🐍 Python-like syntax that runs on Node.js. No Python installation required!

PyScript is a transpiler that converts Python-like syntax into JavaScript, allowing you to write code with Python's elegant syntax while leveraging the entire Node.js ecosystem.

✨ Features

  • 🎯 Python-like syntax - Write code that looks and feels like Python
  • Runs on Node.js - No Python installation required
  • 🔄 Real-time transpilation - Converts your code on the fly
  • 📦 Easy to use - Simple CLI interface
  • 🎨 Beautiful error messages - Clear and helpful error reporting

🚀 Installation

npm install -g pyscript-lang

Or use it locally:

npm install pyscript-lang

📖 Quick Start

Command Line:

# Run a PyScript file
pyscript myfile.pys

# Or use the short alias
pys myfile.pys

Programmatic:

const PyScript = require('pyscript-lang');
const code = 'log("Hello from PyScript!")';
PyScript.run(code);

🎓 Syntax Guide

Print/Log:

log("Hello, World!")
log("Value:", 42, "Multiple", "arguments")

Variables:

name = "PyScript"
age = 2
active = True
nothing = None

Functions:

def greet(name):
    log("Hello,", name)
    return "Greeted!"

def add(a, b):
    return a + b

result = add(5, 3)

Conditionals:

if age > 18:
    log("Adult")
elif age > 13:
    log("Teenager")
else:
    log("Child")

Loops:

# For loop
for i in range(5):
    log("Count:", i)

# While loop
count = 0
while count < 5:
    log(count)
    count += 1

Lists:

fruits = ["apple", "banana", "orange"]
log(fruits[0])

fruits.append("grape")
log(fruits.length)

Dictionaries:

person = {
    "name": "Alice",
    "age": 30,
    "city": "NYC"
}

log(person["name"])
log(person.age)

Classes:

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age
    
    def greet(self):
        log(f"Hi, I'm {self.name}")
    
    def birthday(self):
        self.age += 1

p = Person("Bob", 25)
p.greet()

Import Node.js modules:

import "fs"
import "path" as pathModule

# Use Node.js modules directly!
content = fs.readFileSync("file.txt", "utf8")

String Formatting:

name = "World"
log(f"Hello, {name}!")
log(f"2 + 2 = {2 + 2}")

Try/Except:

try:
    risky_operation()
except error:
    log("Error:", error.message)
finally:
    log("Cleanup")

🎯 Examples

Fibonacci:

def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n - 1) + fibonacci(n - 2)

for i in range(10):
    log(f"Fib({i}) = {fibonacci(i)}")

Simple Web Server:

import "http"

def handle_request(req, res):
    res.writeHead(200, {"Content-Type": "text/plain"})
    res.end("Hello from PyScript!")

server = http.createServer(handle_request)
server.listen(3000)
log("🐍 Server running on port 3000")

🔧 How It Works

PyScript transpiles Python-like syntax to JavaScript in real-time:

  • Parses Python-style code
  • Converts to equivalent JavaScript
  • Executes in Node.js runtime

💡 Why PyScript?

  • Learn Python syntax while using Node.js ecosystem
  • Prototype quickly with Python's clean syntax
  • Bridge Python and JavaScript in your projects
  • Have fun with a unique programming experience

📧 Contact

📝 License

MIT License - Free to use in your projects!

Português

🐍 Sintaxe estilo Python rodando no Node.js. Sem necessidade de instalar Python!

PyScript é um transpilador que converte sintaxe estilo Python em JavaScript, permitindo que você escreva código com a sintaxe elegante do Python enquanto aproveita todo o ecossistema do Node.js.

✨ Recursos

  • 🎯 Sintaxe tipo Python - Escreva código que parece e se sente como Python
  • Roda no Node.js - Não precisa instalar Python
  • 🔄 Transpilação em tempo real - Converte seu código na hora
  • 📦 Fácil de usar - Interface CLI simples
  • 🎨 Mensagens de erro bonitas - Relatórios claros e úteis

🚀 Instalação

npm install -g pyscript-lang

Ou use localmente:

npm install pyscript-lang

📖 Começando

Linha de comando:

# Execute um arquivo PyScript
pyscript meuarquivo.pys

# Ou use o alias curto
pys meuarquivo.pys

Programático:

const PyScript = require('pyscript-lang');
const codigo = 'log("Olá do PyScript!")';
PyScript.run(codigo);

🎓 Guia de Sintaxe

Imprimir/Log:

log("Olá, Mundo!")
log("Valor:", 42, "Múltiplos", "argumentos")

Variáveis:

nome = "PyScript"
idade = 2
ativo = True
nada = None

Funções:

def saudar(nome):
    log("Olá,", nome)
    return "Saudado!"

def somar(a, b):
    return a + b

resultado = somar(5, 3)

Condicionais:

if idade > 18:
    log("Adulto")
elif idade > 13:
    log("Adolescente")
else:
    log("Criança")

Loops:

# Loop for
for i in range(5):
    log("Contagem:", i)

# Loop while
contador = 0
while contador < 5:
    log(contador)
    contador += 1

Listas:

frutas = ["maçã", "banana", "laranja"]
log(frutas[0])

frutas.append("uva")
log(frutas.length)

Dicionários:

pessoa = {
    "nome": "Alice",
    "idade": 30,
    "cidade": "SP"
}

log(pessoa["nome"])
log(pessoa.idade)

Classes:

class Pessoa:
    def __init__(self, nome, idade):
        self.nome = nome
        self.idade = idade
    
    def saudar(self):
        log(f"Oi, eu sou {self.nome}")
    
    def aniversario(self):
        self.idade += 1

p = Pessoa("Bob", 25)
p.saudar()

Importar módulos Node.js:

import "fs"
import "path" as moduloPath

# Use módulos Node.js diretamente!
conteudo = fs.readFileSync("arquivo.txt", "utf8")

Formatação de Strings:

nome = "Mundo"
log(f"Olá, {nome}!")
log(f"2 + 2 = {2 + 2}")

Try/Except:

try:
    operacao_arriscada()
except erro:
    log("Erro:", erro.message)
finally:
    log("Limpeza")

🎯 Exemplos

Fibonacci:

def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n - 1) + fibonacci(n - 2)

for i in range(10):
    log(f"Fib({i}) = {fibonacci(i)}")

Servidor Web Simples:

import "http"

def processar_requisicao(req, res):
    res.writeHead(200, {"Content-Type": "text/plain"})
    res.end("Olá do PyScript!")

servidor = http.createServer(processar_requisicao)
servidor.listen(3000)
log("🐍 Servidor rodando na porta 3000")

🔧 Como Funciona

PyScript transpila sintaxe tipo Python para JavaScript em tempo real:

  • Analisa o código estilo Python
  • Converte para JavaScript equivalente
  • Executa no runtime do Node.js

💡 Por Que PyScript?

  • Aprenda sintaxe Python usando o ecossistema Node.js
  • Prototipe rapidamente com a sintaxe limpa do Python
  • Una Python e JavaScript nos seus projetos
  • Divirta-se com uma experiência de programação única

📧 Contato

📝 Licença

Licença MIT - Livre para usar nos seus projetos!

Made with 💙 by capybarascript

Write Python, Run JavaScript 🐍

Keywords

python

FAQs

Package last updated on 04 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts