{"id":10171,"library":"python3-ldap","title":"python3-ldap (Renamed to ldap3)","description":"The `python3-ldap` project has been renamed to `ldap3`. This entry documents `python3-ldap` as a deprecated library and strongly advises users to migrate to `ldap3`, which is the actively maintained and current library for interacting with LDAP servers in Python. `ldap3` provides a comprehensive, modern, and high-performance feature set for LDAP client operations, including secure connections (LDAPS/StartTLS), asynchronous operations, and various authentication methods. The current version of `ldap3` is 2.9.1, and it maintains a steady release cadence.","status":"renamed","version":"0.9.8.4","language":"en","source_language":"en","source_url":"https://github.com/cannatag/ldap3","tags":["ldap","authentication","directory","enterprise"],"install":[{"cmd":"pip install python3-ldap","lang":"bash","label":"Deprecated: Do not use for new projects"},{"cmd":"pip install ldap3","lang":"bash","label":"Recommended: Install ldap3 instead"}],"dependencies":[{"reason":"Required by ldap3 for ASN.1 encoding/decoding.","package":"pyasn1","optional":false},{"reason":"Required by ldap3 for additional ASN.1 modules.","package":"pyasn1-modules","optional":false}],"imports":[{"note":"The entire API and import structure has changed from `python3-ldap` to `ldap3`. Direct migration is not possible; code must be refactored.","wrong":"from ldap.ldapobject import LDAPObject","symbol":"Server","correct":"from ldap3 import Server"},{"symbol":"Connection","correct":"from ldap3 import Connection"},{"symbol":"AUTH_SIMPLE","correct":"from ldap3 import AUTH_SIMPLE"},{"symbol":"GET_DSE_INFO","correct":"from ldap3 import GET_DSE_INFO"}],"quickstart":{"code":"import os\nfrom ldap3 import Server, Connection, AUTH_SIMPLE, STRATEGY_SYNC, GET_DSE_INFO\n\n# Configure LDAP connection details\nLDAP_SERVER_IP = os.environ.get('LDAP_SERVER_IP', 'your_ldap_server.example.com')\nLDAP_USER_DN = os.environ.get('LDAP_USER_DN', 'cn=admin,dc=example,dc=com') # e.g., 'uid=user,ou=users,dc=example,dc=com'\nLDAP_PASSWORD = os.environ.get('LDAP_PASSWORD', 'admin_password')\nLDAP_BASE_DN = os.environ.get('LDAP_BASE_DN', 'dc=example,dc=com')\n\ntry:\n    # Define the LDAP server\n    server = Server(LDAP_SERVER_IP, get_info=GET_DSE_INFO)\n\n    # Establish a connection\n    conn = Connection(server, user=LDAP_USER_DN, password=LDAP_PASSWORD, authentication=AUTH_SIMPLE)\n\n    # Bind to the server\n    if not conn.bind():\n        print(f\"Error binding to LDAP: {conn.result}\")\n    else:\n        print(\"Successfully bound to LDAP server.\")\n\n        # Perform a search\n        search_filter = '(objectClass=person)' # Example filter\n        conn.search(LDAP_BASE_DN, search_filter, attributes=['cn', 'mail'])\n\n        print(\"\\nSearch Results:\")\n        for entry in conn.entries:\n            print(f\"  CN: {entry.cn}, Mail: {entry.mail}\")\n\n    # Unbind from the server\n    conn.unbind()\n    print(\"Unbound from LDAP server.\")\n\nexcept Exception as e:\n    print(f\"An error occurred during LDAP operation: {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Immediately migrate to `ldap3`. Install with `pip install ldap3` and refactor your code according to `ldap3`'s API documentation.","message":"The `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.","severity":"breaking","affected_versions":"All versions of `python3-ldap` (0.9.8.4 and earlier)."},{"fix":"There is no direct migration path. You must rewrite your LDAP interaction logic using `ldap3`'s `Server` and `Connection` classes and its new query syntax.","message":"The 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.","severity":"breaking","affected_versions":"All versions when migrating from `python3-ldap` to `ldap3`."},{"fix":"Avoid `python3-ldap`. If you encounter installation issues, it's a strong signal to switch to `ldap3`, which has broad compatibility with current Python versions.","message":"Installing `python3-ldap` might fail on modern Python versions or specific operating systems due to outdated dependencies or lack of wheel support.","severity":"gotcha","affected_versions":"Python 3.9+ and potentially certain OS environments."}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure you are importing from `ldap3`. For example, replace `import ldap` or `from ldap import initialize` with `from ldap3 import Server, Connection`.","cause":"Attempting to import `ldap` (or `python3-ldap` modules) when only `ldap3` is installed, or after a partial migration.","error":"No module named 'ldap'"},{"fix":"The `ldap3` library uses `Server` and `Connection` classes. Replace `ldap.initialize(...)` with `server = Server(...)` and `conn = Connection(server, ...)`.","cause":"Trying to use an old `python-ldap` or `python3-ldap` API function (`ldap.initialize`) with the `ldap3` library.","error":"AttributeError: 'module' object has no attribute 'initialize'"},{"fix":"Do not attempt to install `python3-ldap`. Instead, use `pip install ldap3`. `ldap3` is actively maintained and provides wheels for current Python versions.","cause":"The `python3-ldap` package is very old and often lacks pre-built wheels for modern Python versions or architectures, requiring a build from source which might fail.","error":"`python3-ldap` is not a supported wheel on this platform."}]}