Wrapper around good ol' python-ldap.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Бородин Роман ef69f2a53d avoid referrals 5 years ago
ldappr avoid referrals 5 years ago
.gitignore ignore MANIFEST 8 years ago
CHANGES.rst Added type() method to determine type of Directory (e.g. eDirectory) 8 years ago
LICENSE.txt first commit after rename 8 years ago
MANIFEST.in override of cidicts __getitem__ 8 years ago
README.rst README.md to README.rst 8 years ago
setup.py once and for all: binary attr values fix 8 years ago



|PyPI version|

Ldappr is a wrapper around python-ldap, meant for quick and easy handling of common administrative tasks concerning your LDAP compliant repository. It is particularly useful in small, one-time scripts to get things done, or interactively within an iPython shell.


Of course, python-ldap is supposed to be already installed.


pip install ldappr


.. code:: python

import ldappr

# authenticated bind
ldap = ldappr.connect_to('', 'uid=admin,ou=system', 'secret')

Retrieve objects

When you have a connection, you can search on it. First, specify the
seach base.

.. code:: python

ldap.search_base = 'ou=users,ou=system'

Then, get one or more objects to manipulate.

.. code:: python

# retrieve a single object
user = ldap.get('cn=jdoe')

# retrieve a list of objects
users = ldap.search('objectClass=inetOrgPerson')

Do stuff

Once you got an object, you can easily manipulate it. All changes will immediately reflect in your LDAP repository.

.. code:: python

# pretty print the retrieved user

# get an attribute value
sn = user.attrs['sn']

# set an attribute value (existing value will be removed)
user.set_value('givenName', 'Jack')

# add a value to a multi-valued attribute
user.add_value('mobile', '0123456789')
user.add_value('mobile', '9876543210')

# remove a value from a multi-valued attribute
user.remove_value('mobile', '9876543210')

Other examples

.. code:: python

# anonymous bind
ldap = ldappr.connect_to('')

# authenticated bind with more options
ldap = ldappr.connect_to('', 'uid=admin,ou=system', 'secret',
protocol='ldaps', port='10636', verify=False,

# delete all objects with employeeType manager
for dn in ldap.get_dn('employeeType=manager'):

# set an attribute value for a known dn
ldap.set_value('cn=jdoe,ou=users,ou=system', 'givenName', 'Jack')

# make an LDIF export for all users
with open('export.ldif', 'a') as file:
for user in ldap.search('objectClass=inetOrgPerson'):

.. |PyPI version| image:: https://badge.fury.io/py/ldappr.svg
:target: http://badge.fury.io/py/ldappr