HTTP NTLM authentication for HTTPX

1.4.0 · active · verified Thu Apr 16

httpx-ntlm is a Python package that provides NTLM (NT LAN Manager) authentication support for the HTTPX asynchronous HTTP client library. As of version 1.4.0, it allows users to authenticate against NTLM-protected resources, adapting functionality from the requests-ntlm library. It maintains an active status with infrequent but relevant updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic NTLM authentication using `httpx-ntlm` with both a direct `httpx.get` call and a more efficient `httpx.Client` instance for connection pooling. Remember to replace the placeholder URL and set NTLM_USERNAME and NTLM_PASSWORD environment variables with actual credentials.

import httpx
from httpx_ntlm import HttpNtlmAuth
import os

# Using direct request (less efficient for multiple requests)
response = httpx.get(
    "http://ntlm_protected_site.com",
    auth=HttpNtlmAuth(os.environ.get('NTLM_USERNAME', 'domain\\username'), os.environ.get('NTLM_PASSWORD', 'password'))
)
print(f"Direct request status: {response.status_code}")

# Using httpx.Client for connection pooling (recommended for multiple requests)
with httpx.Client(
    auth=HttpNtlmAuth(os.environ.get('NTLM_USERNAME', 'domain\\username'), os.environ.get('NTLM_PASSWORD', 'password'))
) as client:
    response = client.get('http://ntlm_protected_site.com/resource')
    print(f"Client request status: {response.status_code}")

view raw JSON →