Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

Module for Python 3 to access LDAP directory servers.

Project Description

This is a module for handling LDAP operations in Python. Uses libldap2 on Unix platforms and WinLDAP on Microsoft Windows. LDAP entries are mapped to a special Python case-insensitive dictionary, tracking the changes of the dictionary to modify the entry on the server easily.

Support only Python 3.3 or newer, and LDAPv3.

Requirements for building

  • python3.3-dev or newer
  • libldap2-dev
  • libsasl2-dev


  • Uses LDAP libraries (OpenLDAP and WinLDAP) written in C for faster processing.
  • Simple pythonic design.
  • Implements an own dictionary-like object for mapping LDAP entries that makes easier to add and modify them.
  • Works with various asynchronous library (like asyncio, gevent).


Simple search and modify:

import bonsai

client = bonsai.LDAPClient("ldap://localhost")
client.set_credentials("SIMPLE", ("cn=admin,dc=local", "secret"))
with client.connect() as conn:
    res ="ou=nerdherd,dc=local", 2, "(cn=chuck)")
    res[0]['givenname'] = "Charles"
    res[0]['sn'] = "Carmichael"

Using with asnycio:

import asyncio
import bonsai

def do():
    client = bonsai.LDAPClient("ldap://localhost")
    client.set_credentials("DIGEST-MD5", ("admin", "secret", None, None))
    with (yield from client.connect(async=True)) as conn:
        res = yield from"ou=nerdherd,dc=local", 2)
        who = yield from conn.whoami()


Documentation is available online with a simple tutorial.


Currently, you can read the changelog here.


Any contributions and advices are welcome. Please report any issues at the GitHub page.

Release History

Release History

This version
History Node


History Node


Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting