{"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.","language":"python","status":"renamed","last_verified":"Fri Apr 17","install":{"commands":["pip install python3-ldap","pip install ldap3"],"cli":null},"imports":["from ldap3 import Server","from ldap3 import Connection","from ldap3 import AUTH_SIMPLE","from ldap3 import GET_DSE_INFO"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}