Django ESI

9.2.0 · active · verified Thu Apr 16

Django ESI is a Django app that provides a streamlined interface for interacting with the EVE Stable Interface (ESI), the official API for EVE Online. It facilitates dynamic client generation for public and private ESI endpoints, supports EVE Online Single Sign-On (SSO) for character authentication and token retrieval, and offers control over ESI endpoint versions. As of version 9.2.0, it is actively maintained by the Alliance Auth development team and builds upon the `aiopenapi3` library for OpenAPI 3 support.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `django-esi` in a minimal Django context, instantiate the `ESIClientProvider`, and make a simple request to a public ESI endpoint (e.g., fetching EVE Universe type information). It highlights the importance of `compatibility_date`, User-Agent information, and optional tag/operation filtering for memory optimization. Note that `ESI_SSO_CLIENT_ID`, `ESI_SSO_CLIENT_SECRET`, and `ESI_SSO_CALLBACK_URL` are generally required settings even if not directly used in a public endpoint call.

import os
from django.conf import settings

# Minimal Django settings for standalone execution (in a real project, these would be in settings.py)
if not settings.configured:
    settings.configure(
        INSTALLED_APPS=['esi'],
        SECRET_KEY=os.environ.get('DJANGO_SECRET_KEY', 'a-very-secret-key-for-dev'),
        # Required for EVE SSO, even if not used in this specific public API example
        ESI_SSO_CLIENT_ID=os.environ.get('ESI_SSO_CLIENT_ID', 'test-dummy'),
        ESI_SSO_CLIENT_SECRET=os.environ.get('ESI_SSO_CLIENT_SECRET', 'test-dummy'),
        ESI_SSO_CALLBACK_URL=os.environ.get('ESI_SSO_CALLBACK_URL', 'http://localhost:8000/sso/callback'),
        ESI_USER_CONTACT_EMAIL=os.environ.get('ESI_USER_CONTACT_EMAIL', 'your_email@example.com'),
        DEBUG=True # Useful for development, disables some client filters
    )

from esi.openapi_clients import ESIClientProvider

# Instantiate the ESI client provider
# It's strongly recommended to re-use this client wherever possible (e.g., as a global or singleton).
# For best results, use a compatibility_date that you genuinely tested against.
# ua_appname should be PascalCase and ua_version semantic versioning.
# For development, you can set DEBUG=True in Django settings to temporarily bypass tag/operation filtering.
esi_client = ESIClientProvider(
    compatibility_date="2024-07-23", 
    ua_appname="MyDjangoApp", 
    ua_version="0.1.0",
    # Filtering is crucial for memory efficiency in production
    # Example: operations=["GetAlliances"], tags=["Universe"]
    tags=["Universe"]
)

# Example: Fetching a EVE Universe type (e.g., for 'Vexor')
try:
    # Using the filtered client to access the Universe tag
    type_id = 603
    vexor_info = esi_client.client.Universe.GetUniverseTypesTypeId(type_id=type_id).results()
    print(f"Fetched EVE Type (ID: {type_id}): {vexor_info.name}")

    # Example of localized response
    vexor_info_ko = esi_client.client.Universe.GetUniverseTypesTypeId(
        type_id=type_id, Accept_Language='ko'
    ).results()
    print(f"Fetched EVE Type in Korean (ID: {type_id}): {vexor_info_ko.name}")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →