Install & Compatibility
Where this runs
tested against v2.9.13.20260518 · 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.940 runs
installs and imports cleanly · install 0.0s · import 0.264s · 23.8MB
glibcpy 3.10–3.940 runs
installs and imports cleanly · install 1.7s · import 0.255s · 24MB
22MB installed
● package 22MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Server, Connection
✓ from ldap3 import Server, Connection
`types-ldap3` does not provide any runtime imports; it only adds type information to the `ldap3` library. All imports should be directly from `ldap3`.
This quickstart demonstrates a basic LDAP connection and search using the `ldap3` library. By installing `types-ldap3`, type checkers like MyPy can now provide accurate type suggestions and detect errors in this code, enhancing development quality without changing the runtime behavior.
import os
from ldap3 import Server, Connection, AUTH_SIMPLE, STRATEGY_SYNC
# Configure LDAP connection details (replace with your server/credentials)
LDAP_SERVER = os.environ.get('LDAP_SERVER', 'ldap.forumsys.com') # Example public LDAP server
LDAP_PORT = int(os.environ.get('LDAP_PORT', '389'))
LDAP_USER = os.environ.get('LDAP_USER', 'cn=read-only-admin,dc=example,dc=com')
LDAP_PASSWORD = os.environ.get('LDAP_PASSWORD', 'password')
try:
# Initialize LDAP server and connection
server = Server(LDAP_SERVER, port=LDAP_PORT)
conn = Connection(server,
user=LDAP_USER,
password=LDAP_PASSWORD,
authentication=AUTH_SIMPLE,
strategy=STRATEGY_SYNC)
# Bind to the server
if not conn.bind():
print(f"LDAP bind failed: {conn.result}")
exit(1)
print(f"Successfully connected to LDAP server: {LDAP_SERVER}")
# Example: Perform a search operation
search_base = 'dc=example,dc=com'
search_filter = '(objectClass=person)'
conn.search(search_base, search_filter, attributes=['cn', 'mail'])
print(f"Found {len(conn.entries)} entries:")
for entry in conn.entries:
print(f" CN: {entry.cn}, Mail: {entry.mail}")
# Unbind from the server
conn.unbind()
print("Connection unbound.")
except Exception as e:
print(f"An error occurred: {e}")
Upgrade
Version history
2.9.13.20260518latest on PyPI · released May 18, 2026
Audit
Dependencies
ldap3requiredThis package provides type stubs for the `ldap3` library; `ldap3` itself is required for runtime functionality.