Skip to main content
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.8 to 1.10, and Python 2.7/3.4/3.5.

Installing django-ldapdb

Use pip: pip install django-ldapdb

You might also need the usual LDAP packages from your distribution, usually named openldap or ldap-utils.

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',
     },
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
     },
}
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

and add this to your admin.py:

from django.contrib import admin
from . import models

class LDAPGroupAdmin(admin.ModelAdmin):
    exclude = ['dn', 'objectClass']
    list_display = ['gid', 'name']

admin.site.register(models.LDAPGroup, LDAPGroupAdmin)
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.

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.7.0.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_ldapdb-0.7.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-ldapdb-0.7.0.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-ldapdb-0.7.0.tar.gz
Algorithm Hash digest
SHA256 a325cb750c36fa2b48b597ab36ed3a0c8c0711e2f1a149891fa309325b07551f
MD5 0bddf901acdbde150e9a78aac0278f62
BLAKE2b-256 16212208adac164f9eb6eb6e223523b93d9b2f1ad8481eb6250e3d52f78045ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_ldapdb-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 586d15469f79ed0bae91237062dc6c0e5f6f5d7cb3cab252d3380917ab4c2316
MD5 6bdcf2c62d8d8b8e32f060ac4c044e57
BLAKE2b-256 7d2c7ce08724f1a9aecdbed8b61aa33fa8a0e75dead957aa8f5b72455ee2e03c

See more details on using hashes here.

Release history Release notifications | RSS feed

1.5.1

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.9.0

2 files

0.8.0

2 files

This release

0.7.0 This release

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

1 file

0.3.2

1 file

0.3.1

1 file

0.1.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page