|
| 1 | +# 🐍 Python Playground |
| 2 | + |
| 3 | +A modern web-based Python playground built with Vue 3, Vite, Monaco Editor, and Pyodide. Write and execute Python code directly in your browser! |
| 4 | + |
| 5 | +## ✨ Features |
| 6 | + |
| 7 | +- 🎯 **Real-time Python execution** - Run Python code instantly in the browser |
| 8 | +- 📝 **Monaco Editor** - Full-featured code editor with syntax highlighting, autocomplete, and error detection |
| 9 | +- 🎨 **Modern UI** - Beautiful, responsive interface built with Vue 3 |
| 10 | +- 📚 **Code Examples** - Pre-built examples to get you started quickly |
| 11 | +- 📁 **File Upload** - Upload and load Python files (.py, .txt, .pyw) directly into the editor |
| 12 | +- 💾 **Download Code** - Save your work as a Python file |
| 13 | +- 📦 **Package Manager** - Install and manage Python packages on-demand |
| 14 | +- 🔥 **Zero Setup** - No Python installation required, everything runs in the browser |
| 15 | +- 📱 **Responsive Design** - Works great on desktop and mobile devices |
| 16 | + |
| 17 | +## 🚀 Technologies Used |
| 18 | + |
| 19 | +- **Frontend Framework**: Vue 3 with TypeScript |
| 20 | +- **Build Tool**: Vite |
| 21 | +- **Code Editor**: @guolao/vue-monaco-editor |
| 22 | +- **Python Runtime**: Pyodide |
| 23 | +- **State Management**: Pinia |
| 24 | +- **Styling**: Modern CSS with responsive design |
| 25 | + |
| 26 | +## 🛠️ Getting Started |
| 27 | + |
| 28 | +### Prerequisites |
| 29 | + |
| 30 | +- Node.js (version 16 or higher) |
| 31 | +- npm or yarn |
| 32 | + |
| 33 | +### Installation |
| 34 | + |
| 35 | +1. Clone the repository: |
| 36 | +```bash |
| 37 | +git clone https://github.com/hypnguyen1209/python-playground.git |
| 38 | +cd python-playground |
| 39 | +``` |
| 40 | + |
| 41 | +2. Install dependencies: |
| 42 | +```bash |
| 43 | +npm install |
| 44 | +``` |
| 45 | + |
| 46 | +3. Start the development server: |
| 47 | +```bash |
| 48 | +npm run dev |
| 49 | +``` |
| 50 | + |
| 51 | +4. Open your browser and navigate to `http://localhost:5173` |
| 52 | + |
| 53 | +## 📋 Available Scripts |
| 54 | + |
| 55 | +- `npm run dev` - Start the development server |
| 56 | +- `npm run build` - Build for production |
| 57 | +- `npm run preview` - Preview the production build |
| 58 | +- `npm run lint` - Run ESLint |
| 59 | +- `npm run format` - Format code with Prettier |
| 60 | + |
| 61 | +## 🎯 Usage |
| 62 | + |
| 63 | +1. **Write Code**: Use the Monaco Editor on the left to write your Python code |
| 64 | +2. **Upload Files**: Click "Upload File" to load existing Python files into the editor |
| 65 | +3. **Run Code**: Click the "Run Code" button to execute your Python code |
| 66 | +4. **View Output**: See the results in the output panel on the right |
| 67 | +5. **Load Examples**: Use the dropdown to load pre-built code examples |
| 68 | +6. **Install Packages**: Use the package manager panel to install additional Python libraries |
| 69 | +7. **Download Code**: Save your work using the "Download" button |
| 70 | +8. **Clear Output**: Use the "Clear Output" button to reset the output panel |
| 71 | + |
| 72 | +## 📦 Available Python Packages |
| 73 | + |
| 74 | +The playground comes with Python's standard library. Additional packages can be installed on-demand using Pyodide's package system. Common packages include: |
| 75 | + |
| 76 | +- **numpy** - Numerical computing |
| 77 | +- **pandas** - Data analysis and manipulation |
| 78 | +- **matplotlib** - Plotting and visualization |
| 79 | +- **scipy** - Scientific computing |
| 80 | +- **pycryptodome** - Crypto library |
| 81 | +- **requests** - HTTP library |
| 82 | +- **beautifulsoup4** - Web scraping |
| 83 | +- **micropip** - Package installer for Pyodide |
| 84 | + |
| 85 | +## 🎯 Example Code |
| 86 | + |
| 87 | +The playground includes several built-in examples: |
| 88 | + |
| 89 | +1. **Hello World** - Basic Python syntax |
| 90 | +2. **Data Structures** - Lists, dictionaries, and sets |
| 91 | +3. **Loops and Functions** - Control flow and function definitions |
| 92 | +4. **Data Analysis** - Statistics and data processing |
| 93 | +5. **File Processing** - Text analysis (great for testing uploads!) |
| 94 | +6. **Object-Oriented Programming** - Classes and objects |
| 95 | + |
| 96 | +## 🚀 Live Demo |
| 97 | + |
| 98 | +🌐 **Live Demo**: [https://hypnguyen1209.github.io/python-playground/](https://hypnguyen1209.github.io/python-playground/) |
| 99 | + |
| 100 | +The application features: |
| 101 | + |
| 102 | +1. Write or upload Python code |
| 103 | +2. Click "Run Code" to execute |
| 104 | +3. View results in real-time |
| 105 | +4. Install packages as needed |
| 106 | +5. Download your work when done |
| 107 | + |
| 108 | +## 🔧 Architecture |
| 109 | + |
| 110 | +- **Frontend**: Vue 3 with Composition API and TypeScript |
| 111 | +- **Editor**: Monaco Editor (same as VS Code) with Python language support |
| 112 | +- **Python Runtime**: Pyodide (CPython compiled to WebAssembly) |
| 113 | +- **State Management**: Pinia for reactive state |
| 114 | +- **Build System**: Vite with modern ES modules |
| 115 | +- **Styling**: CSS Grid/Flexbox with responsive design |
| 116 | + |
| 117 | +## 🤝 Contributing |
| 118 | + |
| 119 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 120 | + |
| 121 | +## 🐛 Troubleshooting |
| 122 | + |
| 123 | +### Common Issues |
| 124 | + |
| 125 | +**Pyodide Loading Slowly** |
| 126 | +- Pyodide downloads ~6MB on first load |
| 127 | +- Subsequent loads are cached by the browser |
| 128 | +- Check browser console for loading progress |
| 129 | + |
| 130 | +**Package Installation Fails** |
| 131 | +- Not all PyPI packages are available in Pyodide |
| 132 | +- Check [Pyodide package list](https://pyodide.org/en/stable/usage/packages-in-pyodide.html) |
| 133 | +- Some packages may require additional setup |
| 134 | + |
| 135 | +**Code Execution Errors** |
| 136 | +- Check Python syntax in the editor |
| 137 | +- Some advanced Python features may not be supported |
| 138 | +- File system operations are limited in browser environment |
| 139 | + |
| 140 | +### Browser Compatibility |
| 141 | + |
| 142 | +- **Chrome/Edge**: Full support ✅ |
| 143 | +- **Firefox**: Full support ✅ |
| 144 | +- **Safari**: Full support ✅ |
| 145 | +- **Mobile browsers**: Basic support ⚠️ |
| 146 | + |
| 147 | +## 🚀 Deployment |
| 148 | + |
| 149 | +### Production Build |
| 150 | + |
| 151 | +```bash |
| 152 | +npm run build |
| 153 | +``` |
| 154 | + |
| 155 | +The build output will be in the `dist/` directory, ready for deployment to any static hosting service. |
| 156 | + |
| 157 | +### GitHub Pages Deployment |
| 158 | + |
| 159 | +This project includes automatic deployment to GitHub Pages via GitHub Actions: |
| 160 | + |
| 161 | +1. **Setup**: The repository includes a `.github/workflows/deploy.yml` workflow file |
| 162 | +2. **Automatic**: Deploys automatically on every push to the `main` branch |
| 163 | +3. **Manual**: Can also be triggered manually from the Actions tab |
| 164 | +4. **Live URL**: Once deployed, access at `https://hypnguyen1209.github.io/python-playground/` |
| 165 | + |
| 166 | +#### Enable GitHub Pages: |
| 167 | +1. Go to your repository Settings |
| 168 | +2. Navigate to "Pages" in the sidebar |
| 169 | +3. Under "Source", select "GitHub Actions" |
| 170 | +4. The workflow will automatically deploy on the next push |
| 171 | + |
| 172 | +### Other Deployment Options |
| 173 | + |
| 174 | +- **Vercel**: `vercel --prod` |
| 175 | +- **Netlify**: Drag & drop the `dist/` folder |
| 176 | +- **Firebase Hosting**: `firebase deploy` |
| 177 | + |
| 178 | +### Environment Variables |
| 179 | + |
| 180 | +No environment variables required - everything runs client-side! |
| 181 | + |
| 182 | +## 📄 License |
| 183 | + |
| 184 | +This project is licensed under the MIT License. |
| 185 | + |
| 186 | +## 🙏 Acknowledgments |
| 187 | + |
| 188 | +- [Pyodide](https://pyodide.org/) - Python in the browser |
| 189 | +- [Monaco Editor](https://microsoft.github.io/monaco-editor/) - Code editor from VS Code |
| 190 | +- [Vue.js](https://vuejs.org/) - Progressive JavaScript framework |
| 191 | +- [Vite](https://vitejs.dev/) - Next generation frontend tooling |
| 192 | + |
| 193 | +--- |
| 194 | + |
| 195 | +**🔥 Powered by hypnguyen1209** |
0 commit comments