Skip to main content

ip based restrictions for repoze.what.

Project description

It is a repoze.what plugin that provides an ip_from predicate.



$ <env>/bin/easy_install repoze.what.plugins.ip


$ <env>/bin/pip install repoze.what.plugins.ip


The source code can be found at


ip_from([allowed=None], [proxies=None]) checks whether REMOTE_ADDR in the environment points to an allowed IP address. If HTTP_X_FORWARDED_FOR is set in the environment (meaning proxy access) then REMOTE_ADDR is treated as a proxy address and HTTP_X_FORWARDED_FOR as an originating IP address.

allowed optional, default - None
A list of IPs to allow access. Can be a string which is then interpreted as a single IP address
proxies optional, default - None

If a list or tuple provided then treated as a list of authorized proxy IP addresses.

If a string or unicode provided then treated as a single IP address.

Any other value - bool(proxies) == True means that all proxies are accepted

You can filter the incoming IP address:

>>> from repoze.what.plugins.ip import ip_from
>>> p = ip_from(allowed=[''])
>>> env = {'REMOTE_ADDR': ''}
>>> p.is_met(env)
>>> env = {'REMOTE_ADDR': ''}
>>> p.is_met(env)

By default proxy access is disabled. You can enable it with proxies=True:

>>> p = ip_from(allowed=[''], proxies=True)
>>> env = {
...     'REMOTE_ADDR': '',           # proxy
...     'HTTP_X_FORWARDED_FOR': ''   # origin
... }
>>> p.is_met(env)

And you can also explicitly specify proxies to allow:

>>> p = ip_from(allowed='', proxies=[''])
>>> env = {
...     'REMOTE_ADDR': '',           # proxy
...     'HTTP_X_FORWARDED_FOR': ''   # origin
... }
>>> p.is_met(env)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repoze.what.plugins.ip-0.2.tar.gz (17.8 kB view hashes)

Uploaded source

Built Distributions

repoze.what.plugins.ip-0.2-py2.6.egg (36.8 kB view hashes)

Uploaded 2 6

repoze.what.plugins.ip-0.2-py2.5.egg (36.9 kB view hashes)

Uploaded 2 5

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page