Framework web declarativo inspirado no React, construído nativamente para Python
Project description
🐍 PyReact - Framework Web Declarativo para Python
PyReact é um framework web declarativo inspirado no React, mas construído nativamente para Python. Permite criar interfaces de usuário reativas, com componentes, hooks e renderização eficiente.
📦 Instalação
Via pip (Recomendado)
pip install pyreact-framework
Via pip (GitHub)
pip install git+https://github.com/wanbnn/pyreact.git
Desenvolvimento Local
git clone https://github.com/wanbnn/pyreact.git
cd pyreact
pip install -e .
🚀 Início Rápido
Criar um Novo Projeto
# Criar projeto
pyreact-framework create meu-app
# Entrar no diretório
cd meu-app
# Iniciar servidor de desenvolvimento
pyreact-framework dev
Exemplo de Contador
from pyreact import h, render, use_state, Component
def Counter(props):
"""Componente de contador funcional"""
count, set_count = use_state(0)
return h('div', {'className': 'counter'},
h('h1', None, f'Contador: {count}'),
h('button', {'onClick': lambda: set_count(count + 1)}, '+'),
h('button', {'onClick': lambda: set_count(count - 1)}, '-')
)
# Renderizar
root = document.getElementById('root')
render(h(Counter, None), root)
✨ Funcionalidades
Componentes Funcionais
def Button(props):
"""Componente de botão reutilizável"""
return h('button', {
'className': 'btn',
'onClick': props.get('onClick')
}, props.get('children'))
Componentes de Classe
class Counter(Component):
"""Componente de contador com estado"""
def __init__(self, props):
super().__init__(props)
self.state = {'count': 0}
def render(self):
return h('div', None,
h('h1', None, f'Count: {self.state["count"]}'),
h('button', {
'onClick': lambda: self.set_state({'count': self.state['count'] + 1})
}, 'Increment')
)
Hooks
from pyreact import use_state, use_effect, use_ref
def MyComponent(props):
# Estado local
count, set_count = use_state(0)
# Efeito colateral
use_effect(lambda: print(f'Count: {count}'), [count])
# Referência
input_ref = use_ref(None)
return h('div', None, f'Count: {count}')
📖 Documentação
📚 Documentação Completa
A documentação completa está disponível no Read the Docs:
🔗 https://pyreact-framework.readthedocs.io/
Conteúdo da Documentação:
-
Getting Started
- Installation
- Quick Start
- Tutorial (Todo App)
-
Core Concepts
- Components
- Props
- State
- Events
- Lifecycle
-
Advanced
- Server-Side Rendering (SSR)
- Routing
- Styling
- Testing
-
API Reference
- Element API
- Component API
- Hooks API
- CLI API
CLI Commands
# Criar novo projeto
pyreact create <nome>
# Iniciar servidor de desenvolvimento
pyreact-framework dev [--port PORT]
# Gerar componente
pyreact generate component <nome>
# Gerar hook
pyreact generate hook <nome>
# Build para produção
pyreact build
API Principal
h(type, props, *children)
Cria um elemento virtual (VNode).
h('div', {'className': 'container'},
h('h1', None, 'Título'),
h('p', None, 'Parágrafo')
)
render(element, container)
Renderiza um elemento no container.
render(h(App, None), document.getElementById('root'))
create_root(container)
Cria uma raiz de renderização (API moderna).
root = create_root(document.getElementById('root'))
root.render(h(App, None))
🧪 Testes
Executar Testes
# Testes unitários
pytest tests/
# Testes E2E
python tests/e2e/test_simple_e2e.py
# Testes A/B
python tests/e2e/test_ab_counter.py
# Com cobertura
pytest tests/ --cov=pyreact
Documentação de Testes
Ver Teste_Documentos/README.md para mais detalhes.
📁 Estrutura do Projeto
pyreact/
├── pyreact/ # Código fonte
│ ├── cli/ # Interface de linha de comando
│ ├── core/ # Núcleo do framework
│ ├── dom/ # Operações DOM
│ ├── server/ # Renderização servidor
│ └── utils/ # Utilitários
├── tests/ # Testes
│ ├── e2e/ # Testes end-to-end
│ └── unit/ # Testes unitários
├── examples/ # Exemplos
├── Teste_Documentos/ # Documentação de testes
├── pyproject.toml # Configuração do projeto
├── README.md # Este arquivo
├── INSTALL.md # Guia de instalação
├── PUBLISH.md # Guia de publicação
└── LICENSE # Licença MIT
🛠️ Desenvolvimento
Configurar Ambiente
# Clonar repositório
git clone https://github.com/wanbnn/pyreact.git
cd pyreact
# Criar ambiente virtual
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
# Instalar dependências
pip install -e .
# Instalar dependências de desenvolvimento
pip install pytest pytest-cov playwright
playwright install chromium
Executar em Desenvolvimento
# Instalar em modo editável
pip install -e .
# Executar testes
pytest tests/ -v
# Criar build
python -m build
📦 Publicação
Build
# Limpar builds anteriores
python -c "import shutil; from pathlib import Path; [shutil.rmtree(p, ignore_errors=True) for p in ['build', 'dist', 'pyreact.egg-info']]"
# Criar build
python -m build
Publicar no PyPI
# Instalar twine
pip install twine
# Verificar build
twine check dist/*
# Publicar no TestPyPI (teste)
twine upload --repository testpypi dist/*
# Publicar no PyPI (oficial)
twine upload dist/*
Ver PUBLISH.md para mais detalhes.
🤝 Contribuindo
Contribuições são bem-vindas! Por favor:
- Fork o projeto
- Crie uma branch para sua feature (
git checkout -b feature/AmazingFeature) - Commit suas mudanças (
git commit -m 'Add some AmazingFeature') - Push para a branch (
git push origin feature/AmazingFeature) - Abra um Pull Request
📝 Licença
Este projeto está licenciado sob a licença MIT - veja o arquivo LICENSE para detalhes.
📞 Contato
- GitHub Issues: https://github.com/wanbnn/pyreact/issues
- Documentação: https://pyreact.readthedocs.io/
- Email: contato@pyreact.dev
🙏 Agradecimentos
- Inspirado no React
- Construído com ❤️ pela comunidade Python
Feito com ❤️ pela comunidade Python
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyreact_framework-1.0.4.tar.gz.
File metadata
- Download URL: pyreact_framework-1.0.4.tar.gz
- Upload date:
- Size: 68.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0871f55f71f52bd6bb00e99e1ac032d017383bb32b0d031e16f11c7eb978cc39
|
|
| MD5 |
045ea87f218b03bc0f0c06dbfcc4436e
|
|
| BLAKE2b-256 |
93bf21b9ea8dddf14f9df34dcf2394c64b4d500c83bf4b4e68fb3bfea95169da
|
File details
Details for the file pyreact_framework-1.0.4-py3-none-any.whl.
File metadata
- Download URL: pyreact_framework-1.0.4-py3-none-any.whl
- Upload date:
- Size: 73.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6310e19ef49fe3175feba4eda65b7140d3a1cd8bf4ba86dc25379c4d12a8d98b
|
|
| MD5 |
390c94874f4d50b54f57da6affc48fa8
|
|
| BLAKE2b-256 |
0aa94876da4029683a9c3b9e04c5ab744896f3053825b31e9d0d098299ca750d
|