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.11 / 2.0, and Python 2.7 / 3.4 / 3.5 / 3.6.

Installing django-ldapdb

Linux

Use pip: pip install django-ldapdb

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

Windows

django-ldapdb depends on the pyldap <https://pypi.python.org/pypi/pyldap> project. Either follow its Windows installation guide, or install a pre-built version from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyldap (choose the .whl file matching your Python/Windows combination, and install it with pip install pyldap-2.4...whl).

and then you can also install django-ldapdb with

pip install django-ldapdb

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.

Tuning django-ldapdb

It is possible to adjust django-ldapdb’s behavior by defining a few parameters in the DATABASE section:

PAGE_SIZE (default: 1000)

Define the maximum size of a results page to be returned by the server

QUERY_TIMEOUT (default: no limit)

Define the maximum time in seconds we’ll wait to get a reply from the server (on a per-query basis).

Metadata

Release files for django-ldapdb 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-ldapdb 1.0.0
File Size Uploaded
django-ldapdb-1.0.0.tar.gz 16.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-ldapdb 1.0.0
File Interpreter ABI Platform
django_ldapdb-1.0.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 36.7 kB

Release files / django-ldapdb-1.0.0.tar.gz

Download URL django-ldapdb-1.0.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a3a2837a6ec9769fc76164b99b86ba2809c987e370bd8986b69018345f9ba682
BLAKE2b-256 checksum
How to use checksums
c3d49100d501d0cbc7295f371087e72b6d7f66dcc2d6162889b43b5a3d95a85b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_ldapdb-1.0.0-py2.py3-none-any.whl

Download URL django_ldapdb-1.0.0-py2.py3-none-any.whl
Size 20.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d0726e29ac96e966ce81dabb0cf0649bf1122fe2f71e65166cb129aebb8843d7
BLAKE2b-256 checksum
How to use checksums
64fd8237c04845fa7393b1a775aef4187c612da2e751de3e996361f5e9c16920
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.5.1

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

This release

1.0.0 This release

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.1.0

1 release 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