Skip to content
A python library for building nginx configuration files programatically
Python
Branch: master
Clone or download
lorencarvalho Merge pull request #7 from linkedin/update_six
Update dependency on six to be more permissive
Latest commit 084dff7 May 4, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs add proper docs Jul 13, 2017
src/nginx Update dependency on six to be more permissive May 4, 2018
test Pull in internal fixes into OSS. Aug 28, 2017
.gitignore Update dependency on six to be more permissive May 4, 2018
.travis.yml
CONTRIBUTING.md Initial commit. Mar 31, 2017
LICENSE Initial commit. Mar 31, 2017
MANIFEST.in Initial commit. Mar 31, 2017
NOTICE Initial commit. Mar 31, 2017
README.md
setup.cfg Drop support for 2.6 Dec 13, 2017
setup.py Update dependency on six to be more permissive May 4, 2018
tox.ini Update dependency on six to be more permissive May 4, 2018

README.md

PyPI Build Status Documentation Status License

nginx-config-builder

A python library for constructing nginx configuration files.

Installation

pip install nginx-config-builder

Usage

This library ships two interfaces to build configuration with, a high level builder API as well as the low level block-based API that the builder makes use of. Consumers can choose whichever makes sense for their use case:

The Builder API

The builder API is expressive and pluggable.

>>> from nginx.config.builder import NginxConfigBuilder
>>> nginx = NginxConfigBuilder(daemon='on')
>>> with nginx.add_server() as server:
...     server.add_route('/foo', proxy_pass='upstream').end()
...
>>> print(nginx)

error_log logs/nginx.error.log;
worker_processes auto;
daemon on;
http {
    include ../conf/mime.types;
    server {
        server_name _;
        location /foo {
            proxy_pass upstream;
        }
    }
}
events {
    worker_connections 1024;
}
 

The Block API

The block api provides more granularity and explicitness at the cost of being substantially more verbose than the builder api.

>>> from nginx.config.api import Config, Section, Location
>>> events = Section('events', worker_connections='1024')
>>> http = Section('http', include='../conf/mime.types')
>>> http.sections.add(
...     Section(
...         'server',
...         Location(
...             '/foo',
...             proxy_pass='upstream',
...         ),
...         server_name='_',
...     )
... )
>>> nginx = Config(
...     events,
...     http,
...     worker_processes='auto',
...     daemon='on',
...     error_log='var/error.log',
... )
>>> print(nginx)

error_log var/error.log;
worker_processes auto;
daemon on;
http {
    include ../conf/mime.types;
    server {
        server_name _;
        location /foo {
            proxy_pass upstream;
        }
    }
}
events {
    worker_connections 1024;
}

Development

Checkout the repo:

git clone git@github.com:linkedin/nginx-config-builder.git

Set up your virtual environment:

cd nginx-config-builder
python setup.py venv
source activate

Install the project and start hacking!

python setup.py develop

Don't forget to write/run tests!

pip install tox
tox

Authors

You can’t perform that action at this time.