Skip to main content

An LDAP database backend for Django

Project description

https://secure.travis-ci.org/django-ldapdb/django-ldapdb.png?branch=master Latest Version Supported Python versions Wheel status License

django-ldapdb is an LDAP database backend for Django, allowing to manipulate LDAP entries through Django models.

It supports most of the same APIs as a Django model:

  • MyModel.objects.create()

  • MyModel.objects.filter(x=1, y__contains=2)

  • Full admin support and browsing

django-ldapdb supports Django versions 1.7 to 1.9, and Python 2.7/3.4/3.5.

Using django-ldapdb

Add the following to your settings.py:

DATABASES = {
    ...
    'ldap': {
        'ENGINE': 'ldapdb.backends.ldap',
        'NAME': 'ldap://ldap.nodomain.org/',
        'USER': 'cn=admin,dc=nodomain,dc=org',
        'PASSWORD': 'some_secret_password',
     }
 }
DATABASE_ROUTERS = ['ldapdb.router.Router']

If you want to access posixGroup entries in your application, you can add something like this to your models.py:

from ldapdb.models.fields import CharField, IntegerField, ListField
import ldapdb.models

class LdapGroup(ldapdb.models.Model):
    """
    Class for representing an LDAP group entry.
    """
    # LDAP meta-data
    base_dn = "ou=groups,dc=nodomain,dc=org"
    object_classes = ['posixGroup']

    # posixGroup attributes
    gid = IntegerField(db_column='gidNumber', unique=True)
    name = CharField(db_column='cn', max_length=200, primary_key=True)
    members = ListField(db_column='memberUid')

    def __str__(self):
        return self.name

    def __unicode__(self):
        return self.name
Important note:

You must declare an attribute to be used as the primary key. This attribute will play a special role, as it will be used to build the Relative Distinguished Name of the entry.

For instance in the example above, a group whose cn is foo will have the DN cn=foo,ou=groups,dc=nodomain,dc=org.

Project details


Download files

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

Source Distribution

django-ldapdb-0.5.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

django_ldapdb-0.5.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file django-ldapdb-0.5.1.tar.gz.

File metadata

File hashes

Hashes for django-ldapdb-0.5.1.tar.gz
Algorithm Hash digest
SHA256 d86d6c345ee90654b67f5274dbf59305e778d7670271770f530a60d992243d1b
MD5 44258d2d36b4049b87fc33365d3079fa
BLAKE2b-256 6293bcb59f9e1da7e3a490e0b58b9a34861af075e9950686d3f8c266bd4b7107

See more details on using hashes here.

File details

Details for the file django_ldapdb-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_ldapdb-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ffe2628b96d9b04b3ceeb1fcd1f3593b1cad26fbb24af777f52a4a6265ccfbd5
MD5 2a9a22b7b78a8a533484f72ea8383dc0
BLAKE2b-256 f1b58059adc4e627b6208ddc475e340c9616b9baf42cadbf5476c17fdf7bf5e8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page