CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-ldap3

tessl install tessl/pypi-ldap3@1.4.0

A strictly RFC 4510 conforming LDAP V3 pure Python client library

Agent Success

Agent success rate when using this tile

81%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.08x

Baseline

Agent success rate without this tile

75%

task.mdevals/scenario-2/

Directory Connection Lifecycle

Manage a directory service session that can authenticate automatically when configured, expose bound state, and close cleanly when finished.

Capabilities

Automatic bind on creation

  • Creating the session with automatic connection enabled immediately establishes the link and reports bound status using the provided credentials. @test
  • If automatic connection is enabled and credentials are invalid, initialization raises AuthenticationFailure and leaves the session unbound. @test

Manual bind and unbind

  • With automatic connection disabled, the session starts unbound, and calling bind authenticates and flips bound status to true; calling unbind returns the session to an unbound state. @test

Rebinding to another account

  • After a successful bind, calling rebind with different credentials updates the active user identity and reports bound status under the new account. @test

Context-managed lifecycle

  • Using the session as a context manager binds on entry (respecting the automatic connection flag) and always unbinds on exit so that bound status is false after the block, even when an exception is raised inside it. @test

Implementation

@generates

API

from dataclasses import dataclass
from typing import Optional, Any, ContextManager


class AuthenticationFailure(Exception):
    """Raised when credentials are rejected."""


@dataclass
class ConnectionConfig:
    uri: str
    user_dn: Optional[str] = None
    password: Optional[str] = None
    use_tls: bool = False
    auto_connect: bool = False


class DirectoryConnection(ContextManager["DirectoryConnection"]):
    config: ConnectionConfig
    client: Any
    last_error: Optional[str]

    def __init__(self, config: ConnectionConfig):
        ...

    def bind(self) -> bool:
        """Open the connection if needed and authenticate with current credentials."""

    def rebind(self, user_dn: str, password: str) -> bool:
        """Switch credentials and authenticate without creating a new session."""

    def unbind(self) -> None:
        """Close the session and clear bound state."""

    def is_bound(self) -> bool:
        """Return True when the underlying session is authenticated."""

    @property
    def bound_user(self) -> Optional[str]:
        """Active distinguished name for the current bound user."""

    def __enter__(self) -> "DirectoryConnection":
        """Enter a managed block and ensure the session is ready for use."""

    def __exit__(self, exc_type, exc, tb) -> None:
        """Always close the session when leaving the managed block."""

Dependencies { .dependencies }

ldap3 { .dependency }

Provides LDAP client primitives for creating, binding, rebinding, and closing directory connections with optional automatic bind support. @satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/ldap3@1.4.x
tile.json