Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

A python library for building nginx configuration files programatically

License

Notifications You must be signed in to change notification settings

MyMusicTaste/incb.old

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI Build Status Documentation Status License

incb

A python library for constructing nginx configuration files based on LinkedIn's nginx-config-builder

Installation

pip install incb

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;
}

Maintainers

Original authors

About

A python library for building nginx configuration files programatically

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%