{"id":7823,"library":"types-ldap3","title":"Typing Stubs for ldap3","description":"types-ldap3 provides type hinting stubs for the popular `ldap3` library, enabling static type checkers like MyPy to validate `ldap3` code. It is part of the Python typeshed project, ensuring up-to-date and high-quality type definitions. This package does not provide any runtime functionality itself but enhances developer experience by catching type-related errors early. It is actively maintained and updated regularly as part of typeshed.","status":"active","version":"2.9.13.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","ldap","mypy","typeshed"],"install":[{"cmd":"pip install types-ldap3 ldap3","lang":"bash","label":"Install with ldap3"},{"cmd":"pip install types-ldap3","lang":"bash","label":"Install stubs only"}],"dependencies":[{"reason":"This package provides type stubs for the `ldap3` library; `ldap3` itself is required for runtime functionality.","package":"ldap3","optional":false}],"imports":[{"note":"`types-ldap3` does not provide any runtime imports; it only adds type information to the `ldap3` library. All imports should be directly from `ldap3`.","symbol":"Server, Connection","correct":"from ldap3 import Server, Connection"}],"quickstart":{"code":"import os\nfrom ldap3 import Server, Connection, AUTH_SIMPLE, STRATEGY_SYNC\n\n# Configure LDAP connection details (replace with your server/credentials)\nLDAP_SERVER = os.environ.get('LDAP_SERVER', 'ldap.forumsys.com') # Example public LDAP server\nLDAP_PORT = int(os.environ.get('LDAP_PORT', '389'))\nLDAP_USER = os.environ.get('LDAP_USER', 'cn=read-only-admin,dc=example,dc=com')\nLDAP_PASSWORD = os.environ.get('LDAP_PASSWORD', 'password')\n\ntry:\n    # Initialize LDAP server and connection\n    server = Server(LDAP_SERVER, port=LDAP_PORT)\n    conn = Connection(server,\n                      user=LDAP_USER,\n                      password=LDAP_PASSWORD,\n                      authentication=AUTH_SIMPLE,\n                      strategy=STRATEGY_SYNC)\n\n    # Bind to the server\n    if not conn.bind():\n        print(f\"LDAP bind failed: {conn.result}\")\n        exit(1)\n\n    print(f\"Successfully connected to LDAP server: {LDAP_SERVER}\")\n\n    # Example: Perform a search operation\n    search_base = 'dc=example,dc=com'\n    search_filter = '(objectClass=person)'\n    conn.search(search_base, search_filter, attributes=['cn', 'mail'])\n\n    print(f\"Found {len(conn.entries)} entries:\")\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(\"Connection unbound.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `ldap3` is installed via `pip install ldap3` in addition to `pip install types-ldap3`.","message":"`types-ldap3` provides only type stubs and no runtime functionality. You must install the actual `ldap3` library for your application to run.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ideally, use the `types-ldap3` version that most closely corresponds to your `ldap3` version. `typeshed` aims to keep stubs up-to-date with recent `ldap3` releases. If issues persist, check the `typeshed` GitHub for specific version compatibility notes or `ldap3` changelogs.","message":"Type checking issues can arise if the version of `types-ldap3` does not match the installed `ldap3` library version, especially after significant API changes in `ldap3`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the `ldap3` library: `pip install ldap3`.","message":"Installing `types-ldap3` alone will not resolve `ModuleNotFoundError: No module named 'ldap3'` at runtime. Stubs are for static analysis, not runtime dependencies.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the `ldap3` library: `pip install ldap3`.","cause":"The `types-ldap3` package provides only type definitions (stubs), not the actual runtime library. You need the `ldap3` package itself.","error":"ModuleNotFoundError: No module named 'ldap3'"},{"fix":"Ensure `types-ldap3` is installed (`pip install types-ldap3`). If it is, verify that its version is compatible with your `ldap3` version. You might need to update or downgrade `ldap3` or check for a specific `types-ldap3` version.","cause":"This error, reported by a type checker like MyPy, indicates that the type stubs for `ldap3` are either missing, incorrect for your `ldap3` version, or not being picked up correctly. It implies that MyPy doesn't know about `ldap3`'s `Server` class.","error":"error: Module 'ldap3' has no attribute 'Server'  [attr-defined]"},{"fix":"Install the type stubs for `ldap3`: `pip install types-ldap3`.","cause":"MyPy reports this when it finds the `ldap3` runtime package but cannot locate corresponding type stubs, meaning it will treat `ldap3` as `Any`.","error":"Skipping analyzing 'ldap3': module is installed, but missing library stubs or py.typed marker"}]}