{"id":19785846,"url":"https://github.com/apaxphoenix/webpy","last_synced_at":"2025-02-28T07:36:59.869Z","repository":{"id":237569831,"uuid":"794775323","full_name":"ApaxPhoenix/WebPy","owner":"ApaxPhoenix","description":"WebPy is a lightweight and intuitive Python framework designed to simplify web development. Whether you're building a small web application or a complex API, WebPy provides the tools you need to get the job done efficiently and effectively.","archived":false,"fork":false,"pushed_at":"2025-02-11T02:46:38.000Z","size":199,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T03:27:07.654Z","etag":null,"topics":["backend","python","web","webframework"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ApaxPhoenix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-01T23:33:19.000Z","updated_at":"2025-02-11T02:46:44.000Z","dependencies_parsed_at":"2024-05-08T17:39:24.726Z","dependency_job_id":"20fd10c9-ac09-4e0c-88fe-2db62da1517f","html_url":"https://github.com/ApaxPhoenix/WebPy","commit_stats":null,"previous_names":["apaxphoenix/webpy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApaxPhoenix%2FWebPy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApaxPhoenix%2FWebPy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApaxPhoenix%2FWebPy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ApaxPhoenix%2FWebPy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ApaxPhoenix","download_url":"https://codeload.github.com/ApaxPhoenix/WebPy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241119548,"owners_count":19912937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","python","web","webframework"],"created_at":"2024-11-12T06:15:53.362Z","updated_at":"2025-02-28T07:36:59.862Z","avatar_url":"https://github.com/ApaxPhoenix.png","language":"Python","readme":"# WebPy\n\nWebPy is a lightweight and intuitive Python framework designed to simplify web development. Whether you're building a small web application or a complex API, WebPy provides the tools you need to get the job done efficiently and effectively.\n\n## Core Features\n\nWebPy comes packed with features to make web development straightforward and enjoyable:\n\n- **Fast HTTP Handling**: Efficiently manage HTTP requests and responses.\n- **Intelligent Routing**: Define routes with ease and flexibility.\n- **Jinja2 Templates**: Create dynamic and reusable HTML templates.\n- **Static File Serving**: Serve static files like CSS, JavaScript, and images effortlessly.\n- **WebSocket Support**: Build real-time applications with WebSocket integration.\n- **Session Management**: Handle user sessions securely and simply.\n- **Middleware System**: Extend functionality with custom middleware.\n- **HTTPS Support**: Secure your application with built-in HTTPS capabilities.\n- **Custom Error Handling**: Define custom error pages and responses.\n\n## Getting Started\n\nTo begin using WebPy, install it via pip:\n\n```bash\npip install webpy\n```\n\nHere’s a suggested project structure to keep your application organized:\n\n```\nproject/\n├── static/          # Static files (CSS, JS, images)\n│   ├── css/\n│   ├── js/\n│   └── images/\n├── templates/       # Jinja2 templates\n├── middleware/      # Custom middleware\n├── routes/          # Route definitions\n└── app.py           # Main application file\n```\n\n## Core Components\n\n### 1. Creating Your First WebPy Application\n\nStarting a WebPy application is simple:\n\n```python\nfrom webpy import WebPy\n\napp = WebPy()\n\nif __name__ == '__main__':\n    app.run(ip='0.0.0.0', port=8080)\n```\n\n### 2. Handling Requests\n\nWebPy makes it easy to handle different types of HTTP requests:\n\n```python\n@app.route('/api/data', methods=['GET', 'POST'])\ndef handle_data(request, response):\n    if request.method == 'GET':\n        page = request.queries.get('page', ['1'])[0]\n        auth_token = request.headers.get('Authorization')\n        \n        response.json({\n            'page': page,\n            'data': 'example'\n        })\n    elif request.method == 'POST':\n        data = request.json()\n        response.api(data)\n```\n\n### 3. Dynamic Routing\n\nDefine dynamic routes to handle variable URL patterns:\n\n```python\n@app.route('/users/\u003cid:int\u003e')\ndef get_user(request, response, id):\n    response.json({'user_id': id})\n\n@app.route('/resources', methods=['GET', 'POST', 'PUT', 'DELETE'])\ndef handle_resource(request, response):\n    response.api({'method': request.method})\n```\n\n### 4. Using Templates\n\nWebPy integrates with Jinja2 for templating:\n\n```html\n\u003c!-- templates/index.html --\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n    \u003chead\u003e\u003ctitle\u003e{{ title }}\u003c/title\u003e\u003c/head\u003e\n    \u003cbody\u003e\n        \u003ch1\u003eWelcome, {{ name }}!\u003c/h1\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\n```python\n@app.route('/')\ndef index(request, response):\n    html = app.render('index.html', title='Home', name='Friend')\n    response.headers['Content-Type'] = 'text/html'\n    response.body = html.encode('utf-8')\n```\n\n## Advanced Features\n\n### 1. Session Management\n\nManage user sessions with ease:\n\n```python\nfrom webpy import Sessions\n\nsessions = Sessions()\n\n@app.route('/login')\ndef login(request, response):\n    sessions.add('session_id', 'user123', expires=3600)\n    response.api({'message': 'Welcome aboard!'})\n\n@app.route('/session-info')\ndef session_info(request, response):\n    session_id = sessions.get('session_id', 'No active session')\n    response.json({'session_id': session_id})\n```\n\n### 2. Middleware\n\nExtend your application with custom middleware:\n\n```python\nfrom webpy import Middleware\n\nmiddleware = Middleware(app)\n\n@middleware.register\ndef logging_middleware(request, response):\n    print(f\"Incoming: {request.method} {request.path}\")\n\n@middleware.register\ndef cors_middleware(request, response):\n    response.headers['Access-Control-Allow-Origin'] = '*'\n\n@app.route('/api/protected')\n@middleware.run()\ndef protected_route(request, response):\n    response.api({'data': 'protected'})\n```\n\n### 3. WebSocket Support\n\nBuild real-time features with WebSocket:\n\n```python\nfrom webpy import Socket\n\nsocket = Socket(app)\n\n@socket.on('connect')\ndef handle_connect(data, conn):\n    print(f\"New connection: {conn}\")\n\n@socket.on('message')\ndef handle_message(data, conn):\n    socket.emit('broadcast', {'message': data['message']})\n\nif __name__ == '__main__':\n    app.run(port=8080)\n    socket.run(port=8081)\n```\n\n### 4. Custom Error Handling\n\nDefine custom error responses:\n\n```python\n@app.error(404)\ndef not_found(request, response):\n    response.json({\n        'error': 'Not Found',\n        'path': request.path\n    })\n\n@app.error(500)\ndef server_error(request, response):\n    response.json({\n        'error': 'Internal Server Error'\n    })\n```\n\n### 5. HTTPS Support\n\nSecure your application with HTTPS:\n\n```python\nif __name__ == '__main__':\n    app.run(\n        ip='0.0.0.0',\n        port=443,\n        certfile='path/to/cert.pem',\n        keyfile='path/to/key.pem'\n    )\n```\n\n## License\n\nWebPy is released under the MIT License. For more details, please refer to the [LICENSE](LICENSE) file.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapaxphoenix%2Fwebpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapaxphoenix%2Fwebpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapaxphoenix%2Fwebpy/lists"}