{"id":15019688,"url":"https://github.com/wynwxst/ports","last_synced_at":"2026-01-21T02:07:14.302Z","repository":{"id":57454259,"uuid":"436589509","full_name":"wynwxst/Ports","owner":"wynwxst","description":"A scalable, customizable, configurable, programmable, webserver framework","archived":false,"fork":false,"pushed_at":"2022-06-15T00:48:31.000Z","size":162,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-30T13:44:58.647Z","etag":null,"topics":["django","flask","html","ports","python","webserver","webservers"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wynwxst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-09T11:21:56.000Z","updated_at":"2022-05-11T10:14:05.000Z","dependencies_parsed_at":"2022-08-29T15:00:20.814Z","dependency_job_id":null,"html_url":"https://github.com/wynwxst/Ports","commit_stats":null,"previous_names":["n30nyx/ports","sleepy97/ports","ehnryu/ports"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wynwxst%2FPorts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wynwxst%2FPorts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wynwxst%2FPorts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wynwxst%2FPorts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wynwxst","download_url":"https://codeload.github.com/wynwxst/Ports/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238706408,"owners_count":19516928,"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":["django","flask","html","ports","python","webserver","webservers"],"created_at":"2024-09-24T19:53:53.497Z","updated_at":"2026-01-21T02:07:14.294Z","avatar_url":"https://github.com/wynwxst.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PORTS\nA scalable, customizable, configurable, programmable, webserver framework\n\n# Installation\nSimply install python and type `pip install ports.py`\n\n# Usage\n\nStart a static server in three lines:\n```python\nfrom ports import APP, static_APP\napp = static_APP()\napp.run()\n```\nthen all files in `www/` will be hosted\n\nStart a dynamic server:\n```python\nfrom ports import APP, static_APP\n\n\napp = APP()\n\n@app.route(\"/\")\ndef index():\n  return \"hi!\"\n@app.route(\"/hi/\") # unlike flask you can put either /hi or /hi/ and it will work fine\ndef hi():\n  return \"hello\"\n@app.route(\"/bye\") # will still work\ndef bye():\n  return \"bye\"\n\napp.run()\n\n```\n\nMake your own handler/framework:\n```python\nfrom ports import APP, static_APP, tools\n\n\napp = APP()\napp.on(\"request\")\ndef frame(app,req):\n  if req.method == \"GET\":\n    if req.path == \"/\":\n      return \"Index (/)\"\napp.run()\n```\n\nMake a response:\n```python\nfrom ports import APP, static_APP, tools, Response\n\n\napp = APP()\napp.route(\"/\")\ndef index():\n  resp = Response(status=\"200 OK\", content=\"hello world thru resp\")\n  resp.headers.add(\"key\",\"value\")\n  return resp\napp.run()\n```\n\nEvents:\n```python\nfrom ports import APP, static_APP, tools, Response\n\n\napp = APP()\napp.route(\"/\")\ndef index():\n  resp = Response(status=\"200 OK\", content=\"hello world thru resp\")\n  resp.headers.add(\"key\",\"value\")\n  return resp\n@app.on(\"bind\")\ndef binded(sock):\n  print(\"connected\")\n# all events can be accessed through app.all_events\napp.run()\n```\n\nTemplate rendering:\n```python\nfrom ports import APP, static_APP, tools\n\n\napp = APP()\n\n@app.route(\"/\")\ndef index():\n  return tools.render_template(\"index.html\")\n\napp.run(\"0.0.0.0\",8080)\n```\nRenders `templates/index.html` ^\n\nArguments:\n```python\nfrom ports import APP, static_APP\n\n\napp = APP()\n\n@app.route(\"/\")\ndef index(req):\n  if req.args == {}:\n    return \"No args\"\n  if \"name\" not in req.args:\n    return \"please give arg 'name'\"\n  name = req.args[\"name\"]\n  return f\"hello {name}\"\n\n\napp.run(\"0.0.0.0\",8080)\n```\n\nCookies:\n```python\nfrom ports import APP, static_APP\n\n\n\napp = APP()\n\n@app.route(\"/\")\ndef index():\n  cookiejar = app.Cookies.get_all() # return in json name:value\n  value = app.Cookies.get(\"pwd\")\n  if \"username\" in cookiejar:\n    app.Cookies.delete(\"username\")\n  else:\n    app.Cookies.set(\"username\",\"example\")\n\napp.run(\"0.0.0.0\",8080)\n```\n\nSend file:\n```python\nfrom ports import APP, static_APP\nfrom ports import tools\n\n\napp = APP()\n@app.route(\"/\")\ndef index():\n  return \"Favicon Activated\"\n@app.route(\"/favicon.ico\")\ndef favicon():\n  return tools.send_file(\"favicon.ico\")\napp.run(\"0.0.0.0\",8080)\n```\n\nExtensions:\n\"app.py\"\n```python\nimport ports\nfrom ports import managers\n\napp = ports.APP(__name__)\next = managers.extensions\next.register(\"extension.py\")\n# to register all \"python\" files in a directory:\n#ext.regdir(\"extensions/\")\n\n\n@app.route(\"/exts/\")\ndef exts():\n  return \"try route /\"\n\n\napp.run()\n```\n\"extension.py\"\n```python\nimport ports\nfrom ports import managers\n\n\n\nclass extension:\n  def __init__(self,app):\n    self.name = \"name of extension\"\n    self.app = app\n  def run(self):\n    @self.app.route(\"/\")\n    def index():\n      return \"hi!\"\n    @self.app.route(\"/hello/\")\n    def hello():\n      return str(self.app.config)\n\ndef setup(app):\n  ext = extension(app)\n  ext.run()\n```\nthe object app is given to the function setup\nsimilarly it can also be used as:\n```python\nimport ports\nfrom ports import managers\n\ndef extension(app):\n  @app.route(\"/\")\n  def index():\n    return \"hi!\"\n  @app.route(\"/hello/\")\n  def hello():\n    return str(app.config)\n\ndef setup(app):\n  extension(app)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwynwxst%2Fports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwynwxst%2Fports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwynwxst%2Fports/lists"}