{"id":15008998,"url":"https://github.com/peakwinter/python-nginx","last_synced_at":"2025-10-08T18:29:33.407Z","repository":{"id":12068746,"uuid":"14655758","full_name":"peakwinter/python-nginx","owner":"peakwinter","description":"Create and modify nginx serverblock configs in Python","archived":false,"fork":false,"pushed_at":"2023-02-22T01:31:22.000Z","size":133,"stargazers_count":299,"open_issues_count":5,"forks_count":78,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-13T20:58:01.650Z","etag":null,"topics":["nginx","nginx-server","nginx-serverblock","python","python-2","python-library","python-nginx","python3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peakwinter.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","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":"2013-11-24T04:32:12.000Z","updated_at":"2025-03-12T15:32:32.000Z","dependencies_parsed_at":"2024-06-18T15:27:30.413Z","dependency_job_id":"6d4aa9ad-eb62-465a-8336-c135364f44c3","html_url":"https://github.com/peakwinter/python-nginx","commit_stats":{"total_commits":88,"total_committers":13,"mean_commits":6.769230769230769,"dds":0.6363636363636364,"last_synced_commit":"c284cdb57e297318937e1259053cfbcb470ea1d7"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peakwinter%2Fpython-nginx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peakwinter%2Fpython-nginx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peakwinter%2Fpython-nginx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peakwinter%2Fpython-nginx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peakwinter","download_url":"https://codeload.github.com/peakwinter/python-nginx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478160,"owners_count":22077675,"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":["nginx","nginx-server","nginx-serverblock","python","python-2","python-library","python-nginx","python3"],"created_at":"2024-09-24T19:22:17.086Z","updated_at":"2025-10-08T18:29:28.359Z","avatar_url":"https://github.com/peakwinter.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## python-nginx\n\n![build](https://github.com/peakwinter/python-nginx/actions/workflows/ci.yml/badge.svg)\n\nA module for easily creating and modifying nginx serverblock configurations in Python (including comments!).\n\n### Install\n\n    pip install python-nginx\n\n### Examples\n\nCreate an nginx serverblock and save it to file:\n\n    \u003e\u003e\u003e import nginx\n    \u003e\u003e\u003e c = nginx.Conf()\n    \u003e\u003e\u003e u = nginx.Upstream('php',\n    ...     nginx.Key('server', 'unix:/tmp/php-fcgi.socket')\n    ...\t)\n    \u003e\u003e\u003e c.add(u)\n    \u003e\u003e\u003e s = nginx.Server()\n    \u003e\u003e\u003e s.add(\n    ...     nginx.Key('listen', '80'),\n    ...     nginx.Comment('Yes, python-nginx can read/write comments!'),\n    ...     nginx.Key('server_name', 'localhost 127.0.0.1'),\n    ...     nginx.Key('root', '/srv/http'),\n    ...     nginx.Key('index', 'index.php'),\n    ...     nginx.Location('= /robots.txt',\n    ...          nginx.Key('allow', 'all'),\n    ...          nginx.Key('log_not_found', 'off'),\n    ...          nginx.Key('access_log', 'off')\n    ...     ),\n    ...     nginx.Location('~ \\.php$',\n    ...          nginx.Key('include', 'fastcgi.conf'),\n    ...          nginx.Key('fastcgi_intercept_errors', 'on'),\n    ...          nginx.Key('fastcgi_pass', 'php')\n    ...     )\n    ... )\n    \u003e\u003e\u003e c.add(s)\n    \u003e\u003e\u003e nginx.dumpf(c, '/etc/nginx/sites-available/mysite')\n\nLoad an nginx serverblock from a file:\n\n    \u003e\u003e\u003e import nginx\n    \u003e\u003e\u003e c = nginx.loadf('/etc/nginx/sites-available/testsite')\n    \u003e\u003e\u003e c.children\n    [\u003cmain.Server object at 0x7f1ed4573890\u003e]\n    \u003e\u003e\u003e c.server.children\n    [\u003cmain.Comment object at 0x7f1ed45736d0\u003e, \u003cmain.Key object at 0x7f1ed4573750\u003e, \u003cmain.Key object at 0x7f1ed4573790\u003e, \u003cmain.Location object at 0x7f1ed4573850\u003e]\n    \u003e\u003e\u003e c.as_dict\n    {'conf': [{'server': [{'#': 'This is a test comment'}, {'server_name': 'localhost'}, {'root': '/srv/http'}, {'location /': [{'allow': 'all'}]}]}]}\n\nFormat an nginx serverblock into a string (change the amount of spaces (or tabs) for each indentation level by modifying `nginx.INDENT` first):\n\n    \u003e\u003e\u003e c.servers\n    [\u003cmain.Server object at 0x7f1ed4573890\u003e]\n    \u003e\u003e\u003e c.as_strings\n    ['server {\\n', '    # This is a test comment\\n', '    server_name localhost;\\n', '    root /srv/http;\\n', '\\n    location / {\\n', '        allow all;\\n', '    }\\n\\n', '}\\n']\n\nFind where you put your keys:\n\n    \u003e\u003e\u003e import nginx\n    \u003e\u003e\u003e c = nginx.loadf('/etc/nginx/sites-available/testsite')\n    \u003e\u003e\u003e c.filter('Server')\n    [\u003cmain.Server object at 0x7f1ed4573890\u003e]\n    \u003e\u003e\u003e c.filter('Server')[0].filter('Key', 'root')\n    [\u003cmain.Key object at 0x7f1ed4573790\u003e]\n    \u003e\u003e\u003e c.filter('Server')[0].filter('Location')\n    [\u003cmain.Location object at 0x7f1ed4573850\u003e]\n\nOr just get everything by its type:\n\n    \u003e\u003e\u003e import nginx\n    \u003e\u003e\u003e c = nginx.loadf('/etc/nginx/sites-available/testsite')\n    \u003e\u003e\u003e c.servers\n    [\u003cmain.Server object at 0x7f1ed4573890\u003e]\n    \u003e\u003e\u003e c.servers[0].keys\n    [\u003cmain.Key object at 0x7f1ed4573750\u003e, \u003cmain.Key object at 0x7f1ed4573790\u003e]\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeakwinter%2Fpython-nginx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeakwinter%2Fpython-nginx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeakwinter%2Fpython-nginx/lists"}