Install & Compatibility
Where this runs
tested against v0.9.8.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.268s · 71.4MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.7s · import 0.252s · 22MB
46MB installed
● package 46MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Server
✓ from ldap3 import Server
✗ from ldap3 import Server
This quickstart demonstrates how to establish a connection to an LDAP server using `ldap3`, bind with simple authentication, and perform a basic search. It's crucial to replace placeholder values with your actual LDAP server details and user credentials. Environment variables are used for sensitive information.
import os
from ldap3 import Server, Connection, AUTH_SIMPLE, STRATEGY_SYNC, GET_DSE_INFO
# Configure LDAP connection details
LDAP_SERVER_IP = os.environ.get('LDAP_SERVER_IP', 'your_ldap_server.example.com')
LDAP_USER_DN = os.environ.get('LDAP_USER_DN', 'cn=admin,dc=example,dc=com') # e.g., 'uid=user,ou=users,dc=example,dc=com'
LDAP_PASSWORD = os.environ.get('LDAP_PASSWORD', 'admin_password')
LDAP_BASE_DN = os.environ.get('LDAP_BASE_DN', 'dc=example,dc=com')
try:
# Define the LDAP server
server = Server(LDAP_SERVER_IP, get_info=GET_DSE_INFO)
# Establish a connection
conn = Connection(server, user=LDAP_USER_DN, password=LDAP_PASSWORD, authentication=AUTH_SIMPLE)
# Bind to the server
if not conn.bind():
print(f"Error binding to LDAP: {conn.result}")
else:
print("Successfully bound to LDAP server.")
# Perform a search
search_filter = '(objectClass=person)' # Example filter
conn.search(LDAP_BASE_DN, search_filter, attributes=['cn', 'mail'])
print("\nSearch Results:")
for entry in conn.entries:
print(f" CN: {entry.cn}, Mail: {entry.mail}")
# Unbind from the server
conn.unbind()
print("Unbound from LDAP server.")
except Exception as e:
print(f"An error occurred during LDAP operation: {e}")
Debug
Known issues
breakingThe `python3-ldap` project is completely abandoned and has been renamed to `ldap3`. It receives no further updates, bug fixes, or security patches. Using `python3-ldap` is not recommended.fixImmediately migrate to `ldap3`. Install with `pip install ldap3` and refactor your code according to `ldap3`'s API documentation.
affects: All versions of `python3-ldap` (0.9.8.4 and earlier).
breakingThe API of `python3-ldap` is entirely incompatible with `ldap3`. Code written for `python3-ldap` will not work with `ldap3` without significant modification, as core classes, functions, and paradigms have changed.fixThere is no direct migration path. You must rewrite your LDAP interaction logic using `ldap3`'s `Server` and `Connection` classes and its new query syntax.
affects: All versions when migrating from `python3-ldap` to `ldap3`.
gotchaInstalling `python3-ldap` might fail on modern Python versions or specific operating systems due to outdated dependencies or lack of wheel support.fixAvoid `python3-ldap`. If you encounter installation issues, it's a strong signal to switch to `ldap3`, which has broad compatibility with current Python versions.
affects: Python 3.9+ and potentially certain OS environments.
Upgrade
Version history
0.9.8.4latest on PyPI · released May 28, 2015
Audit
Dependencies
pyasn1requiredRequired by ldap3 for ASN.1 encoding/decoding.
pyasn1-modulesrequiredRequired by ldap3 for additional ASN.1 modules.