ServLoci SDK Quickstart¶

Open In Colab

The four ways to use the ServLoci Python class.

Part 01 of 20 in the ServLoci algo/options trading notebook series — full index in notebooks/README.md.

Setup¶

# Get your dedicated static IPv6 + SOCKS5 credentials free:
#   https://comm.servloci.in/register        (or /auth/google?free=1 for an instant trial)
# Your api_key / api_secret pair shows up in the portal after signup:
#   https://comm.servloci.in/user
!pip install -q "requests[socks]"
!curl -sL https://comm.servloci.in/sdk/servloci.py -o servloci.py

import os
from servloci import ServLoci

SERVLOCI_API_KEY = os.environ.get("SERVLOCI_API_KEY", "dhan:1000000001")   # broker:client_id
SERVLOCI_API_SECRET = os.environ.get("SERVLOCI_API_SECRET", "")            # from the portal — leave blank to run this notebook in demo mode

sl = None
if SERVLOCI_API_SECRET:
    sl = ServLoci(api_key=SERVLOCI_API_KEY, api_secret=SERVLOCI_API_SECRET)
    print("ServLoci configured:", sl.host, sl.port)
else:
    print("SERVLOCI_API_SECRET not set — running in demo mode (no live proxy calls).")

The SDK has four surfaces: proxy_url() / proxies() for raw URLs, export_env() for env-based tools, session() for a scoped requests.Session, and attach() to monkey-patch every future requests.Session process-wide.

from servloci import ServLoci, configure

demo = ServLoci(api_key="dhan:1000000001", api_secret="demo-secret")
print("proxy_url():", demo.proxy_url())
print("proxies():  ", demo.proxies())

try:
    ServLoci(api_key="", api_secret="")
except ValueError as e:
    print("Missing credentials raise ValueError:", e)

if sl:
    sl.export_env()
    print("HTTPS_PROXY set in os.environ:", "HTTPS_PROXY" in os.environ)
    s = sl.session()
    print("session() proxies:", s.proxies)

attach() must run before you import a broker SDK — dhanhq, kiteconnect, growwapi and fyers-apiv3 all create a requests.Session at import time. The one-liner servloci.configure(api_key, api_secret) does ServLoci(...).attach() in a single call.


« Previous: Get Your Static IP & Verify It
Next: Broker Auth: Zerodha (Kite Connect) »

Try the concepts above interactively: Options Strategy Builder · Docs · Get your static IP