/gawel/afpy.ldap

Previous topic

Welcome to afpy.ldap’s documentation!

Next topic

afpy.ldap.scripts – LDAP Shell

This Page

Installation and configuration

Using easy_install:

$ easy_install afpy.ldap

Edit your ~/.ldap.cfg:

[DEFAULT]
ldap.protocol = ldaps
ldap.host = localhost
ldap.port = 636

[myldap]
ldap.bind_dn = uid=admin,ou=members,dc=exemple,dc=org
ldap.bind_pwd = XXXXXXX

ldap.user_class = myldap:User
ldap.group_class = myldap:Group

Add a myldap.py module to your PYTHON_PATH

# -*- coding: utf-8 -*-
from afpy.ldap.node import User as BaseUser
from afpy.ldap.node import GroupOfNames
from afpy.ldap import schema

class User(BaseUser):
    _rdn = 'uid'
    _base_dn = 'ou=members,dc=exemple,dc=org'

    # default user properties
    _defaults = dict(
        objectClass = ['top', 'person',
                       'organizationalPerson', 'inetOrgPerson'],
        st='FR',
       )
    uid=schema.StringProperty('uid', title='Login')
    sn=schema.UnicodeProperty('sn', title='Nom')
    mail=schema.StringProperty('mail', title='E-mail')

class Group(GroupOfNames):
    _rdn = 'cn'
    _base_dn = 'ou=groups,dc=exemple,dc=org'

Try ldapsh script (see afpy.ldap.scripts – LDAP Shell):

$ ldapsh -h
Usage: ldapsh [options]

Options:
  -h, --help            show this help message and exit
  -s SECTION, --section=SECTION
                        A config section to get ldap info from

$ ldapsh -s myldap

You can now use the Connection class in your own code:

>>> from afpy.ldap.connection import Connection
>>> conn = Connection(section='myldap')

Enjoy !