Skip to main content
The Python SDK ships with three optional adapters for the most common Python web frameworks. Each is installable as a pip extra and provides a thin layer that handles the singleton lifecycle for you. If you don’t use any of these frameworks, ignore this page - the core NexusClient / AsyncNexusClient work everywhere.

Django

Install with the extra:
settings.py:
Every setting is optional. NEXUS_BASE_URL falls back to WESTYX_SERVICE_ENDPOINT; NEXUS_WIF takes a WIFConfig or a mapping of its fields ({"enabled": True, "provider": "kubernetes"}). With neither NEXUS_API_KEY nor NEXUS_WIF the adapter uses Workload Identity Federation with the default provider, which finds the session westyx dev setup wrote - so under westyx dev run it needs no Nexus settings at all. The AppConfig.ready() hook performs the blocking initial sync at Django startup, so by the time any view is called the cache is populated. views.py:
The client is closed automatically when the Django process exits (via atexit).

FastAPI

Install with the extra:
Use the attach_nexus lifespan helper:
The lifespan starts the client (blocking initial sync) before the app accepts requests, and closes it on shutdown. get_nexus is a standard FastAPI dependency - inject it into any handler.

Flask

Install with the extra:
Two patterns are supported (Flask convention):
  • One-shot: NexusExtension(app) - create at module level alongside the app
  • Factory: ext = NexusExtension(); ext.init_app(app) - for the application-factory pattern
Every setting is optional, as for Django. The client is closed automatically when the Flask process exits (via atexit).

Logging

The Django and Flask adapters log through StdlibNexusLogger() - the westyx_nexus logger - unless NEXUS_LOGGER names another, and FastAPI’s attach_nexus takes whatever logger the NexusConfig carries, the same logger by default. So the SDK’s records, the startup summary among them, appear wherever your application’s logging configuration sends westyx_nexus at INFO and above.

Framework settings come from the environment, not from Nexus

DJANGO_SETTINGS_MODULE and the settings Flask reads from its environment are read when the framework starts, before the Nexus integration loads, so a Nexus config of that name changes nothing. Set them in the deployment.

Manual (no adapter)

If you don’t use any of the supported frameworks (or you’re using one in a way the adapter doesn’t fit), you can always instantiate the client directly:
Just remember to call nexus.close() on shutdown (signal handler, atexit, or with block).