Skip to main content

Python 3 module for accessing LDAP directory servers.

Project description

PyPI Version Travis CI Build Status AppVeyor CI Build Status Coverage Status Documentation Status GitHub License

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.

Supports only Python 3.5 or newer, and LDAPv3.

Features

  • 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).

Requirements for building

  • python3.5-dev or newer
  • libldap2-dev
  • libsasl2-dev
  • libkrb5-dev or heimdal-dev (optional)

Documentation

Documentation is available online with a simple tutorial.

Example

Simple search and modify:

import bonsai

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

Using with asyncio (on Python 3.5 or newer):

import asyncio
import bonsai

async def do():
    client = bonsai.LDAPClient("ldap://localhost")
    client.set_credentials("DIGEST-MD5", user="admin", password="secret")
    async with client.connect(is_async=True) as conn:
        res = await conn.search("ou=nerdherd,dc=bonsai,dc=test", 2)
        print(res)
        who = await conn.whoami()
        print(who)

loop = asyncio.get_event_loop()
loop.run_until_complete(do())

Changelog

The changelog is available here and included in the documentation as well.

Contribution

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bonsai, version 1.2.0
Filename, size File type Python version Upload date Hashes
Filename, size bonsai-1.2.0-cp36-cp36m-win32.whl (66.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size bonsai-1.2.0-cp36-cp36m-win_amd64.whl (74.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size bonsai-1.2.0-cp37-cp37m-macosx_10_14_x86_64.whl (1.5 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size bonsai-1.2.0-cp37-cp37m-win32.whl (66.9 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size bonsai-1.2.0-cp37-cp37m-win_amd64.whl (74.4 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size bonsai-1.2.0-cp38-cp38-win32.whl (67.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size bonsai-1.2.0-cp38-cp38-win_amd64.whl (75.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size bonsai-1.2.0.tar.gz (125.8 kB) File type Source Python version None Upload date Hashes View
Filename, size bonsai-1.2.0.win32-py3.6.exe (529.0 kB) File type Windows Installer Python version 3.6 Upload date Hashes View
Filename, size bonsai-1.2.0.win32-py3.7.exe (529.0 kB) File type Windows Installer Python version 3.7 Upload date Hashes View
Filename, size bonsai-1.2.0.win32-py3.8.exe (529.6 kB) File type Windows Installer Python version 3.8 Upload date Hashes View
Filename, size bonsai-1.2.0.win-amd64-py3.6.exe (666.2 kB) File type Windows Installer Python version 3.6 Upload date Hashes View
Filename, size bonsai-1.2.0.win-amd64-py3.7.exe (666.2 kB) File type Windows Installer Python version 3.7 Upload date Hashes View
Filename, size bonsai-1.2.0.win-amd64-py3.8.exe (666.7 kB) File type Windows Installer Python version 3.8 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page