← Country website blocking
SERVER-SIDE COUNTRY RULES · PYTHON

Apply country rules in Python.

Look up the request country, apply your policy and decide before sending protected content.

1. Install and configure

Extract the SDK and run python -m pip install ./path/to/extracted-sdk inside your virtual environment. It requires Python 3.10+. Wrap the existing WSGI/ASGI app before serving protected routes, and supply explicit proxy CIDRs where applicable.

Download Python SDK

Set ORIGOOO_API_KEY on your server. Use a secret key with lookup scope and the API origin https://orig.ooo. These SDKs are source downloads, not public package-registry releases.

2. Apply the rule before your response

This example blocks US and GB, allows other matched countries, and denies when location is unknown. Choose the unknown behaviour for your own service before deployment.

import os
from origooo import Client, Policy, WSGIMiddleware

client = Client(os.environ['ORIGOOO_API_KEY'], base_url='https://orig.ooo')
policy = Policy(blocked=frozenset({'US', 'GB'}), unknown='deny')

def protected_app(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return [b'Allowed content']

# Put the middleware before your existing WSGI application.
app = WSGIMiddleware(protected_app, client, policy, trusted_proxies=[])
# ASGI applications can use ASGIMiddleware with the same client/policy.

Python setup and framework guide →

3. Verify your request path

  1. Verify an allowed country reaches your application handler.
  2. Verify a blocked country returns 403 before protected content is rendered.
  3. Simulate a timeout, 429, missing country and invalid IP; verify your explicit unknown policy.
  4. Confirm untrusted forwarded headers cannot change the visitor IP.
  5. Keep administrator/health-route exceptions in trusted application code.

Choose when to use this

Use server policies for regional service availability and applications with a defined country policy. For an offer or message that merely appears or disappears, use the browser decision element. Browser hiding does not prevent downloading content already sent to the client.

The API supplies approximate geography. VPNs, mobile networks and proxies affect the result. Treat a country rule as one input to your application, not proof of residence.

Complete Python reference → · Error handling · Request speed and credits

YOUR NEXT BUILD STARTS HERE

Get your free API key.

1,000 monthly credits. No credit card required.

Account services are not connected in this preview. Explore the dashboard or download the implementation from your workspace.
Read the integration guide

Production accounts require verified email. Google OAuth and Paddle need deployment credentials.