Registry / auth-security / python-active-directory

python-active-directory

JSON →
library2.0.1pypypiunverified

Python-AD is an Active Directory client library designed for Python on UNIX/Linux systems. It provides a programmatic interface for performing various LDAP and Kerberos operations against Microsoft Active Directory domains. The library currently supports Python 3 environments, with its latest stable release being 2.0.1.

pip install python-active-directory
INSTALL
IMPORT
SIG · PYTHON-ACTIVE-DIRE
P
python-active-directory
auth-securitypythonv2.0.1
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
from activedirectory import Client
from activedirectory import Client

This quickstart demonstrates how to initialize the `Client` for connecting to Active Directory. It expects environment variables for the AD server, username (preferably UPN format), password, and base DN. The example assumes a secure connection using LDAPS on port 636, which is standard. Further interactions like searching for users would rely on methods exposed by the `Client` object, which are to be explored in the library's specific API documentation.

import os from activedirectory import Client # Environment variables for sensitive information AD_SERVER = os.environ.get('AD_SERVER', 'your.ad.domain.com') AD_USERNAME = os.environ.get('AD_USERNAME', 'username@your.ad.domain.com') AD_PASSWORD = os.environ.get('AD_PASSWORD', 'your_password') AD_BASE_DN = os.environ.get('AD_BASE_DN', 'dc=your,dc=ad,dc=domain,dc=com') try: # Initialize the client, assuming typical LDAP over SSL (LDAPS) on port 636 # Note: The exact Client constructor might vary; this is an educated guess based on typical AD client libs. # Consult official documentation or source code for precise constructor arguments. ad_client = Client( host=AD_SERVER, username=AD_USERNAME, password=AD_PASSWORD, base_dn=AD_BASE_DN, use_ssl=True, # Recommended for production port=636 ) print(f"Successfully connected to AD server: {AD_SERVER}") # Example: Search for a user (replace 'testuser' with an actual sAMAccountName) # The library is expected to provide methods for common AD operations. # This part is illustrative as specific methods are not detailed in public search results for 'theatlantic' fork. # For a real implementation, you'd call a search_user or find_object method if available. # For demonstration, let's assume a basic search capability for an object by its sAMAccountName. # The actual implementation would require diving into the library's available methods. print(f"\nAttempting to find user with sAMAccountName: {AD_USERNAME.split('@')[0]}") # In a real scenario, you'd use a dedicated search method like: # user_found = ad_client.search_user(sAMAccountName=AD_USERNAME.split('@')[0]) # For a simple connection test without specific search methods, we'll just confirm connection. # To perform actual searches, you would typically use methods exposed by the Client object, # often involving LDAP filters. # Example of a generic search (hypothetical method): # results = ad_client.search(base_dn=AD_BASE_DN, filter=f'(sAMAccountName={AD_USERNAME.split('@')[0]})') # if results: # print(f"Found user: {results[0].get('cn')}") # else: # print("User not found.") # If the Client object itself doesn't expose a direct 'search' method for this quickstart, # we will just confirm the connection was successful. print("Basic AD client initialized. Further operations depend on specific library methods.") except Exception as e: print(f"Error connecting or interacting with Active Directory: {e}") print("Ensure AD_SERVER, AD_USERNAME, AD_PASSWORD, and AD_BASE_DN are correctly set.")
Debug
Known issues
breakingVersion 2.0 of `python-active-directory` dropped support for Python 2. Projects requiring Python 2 must use an older major version (e.g., 1.x) or migrate to Python 3.
fix
Upgrade your Python environment to Python 3.6 or newer, or pin your library version to `<2.0.0`.
affects: >=2.0.0
gotchaActive Directory by default limits LDAP search results to 1,000 entries. Queries exceeding this limit will result in an error or truncated results if not handled with paged results.
fix
Implement paged results when performing extensive searches. The underlying `python-ldap` library provides `ldap.controls.SimplePagedResultsControl` for this purpose, which this library may wrap.
affects: All
gotchaIncorrect username format (e.g., missing UPN suffix like `@domain.com`) or issues with LDAP referrals can lead to `ldap.INVALID_CREDENTIALS` errors even with correct passwords.
fix
Always use the User Principal Name (UPN) format (e.g., `user@domain.com`) for the username. If experiencing referral issues, ensure your LDAP client configuration handles referrals correctly or disable them if appropriate for your environment.
affects: All
Upgrade
Version history
2.0.1latest on PyPI · released Nov 11, 2022
Audit
Dependencies
python-ldaprequiredCore dependency for LDAP communication with Active Directory.
pyasn1requiredRequired by python-ldap for ASN.1 support.
pyasn1-modulesrequiredRequired by python-ldap for ASN.1 support.
Agent activity
28 hits · last 30 days
node
26
OpenAI (training)
1
Resources
python-active-directory — pip install python-active-directory · libregistry