[python-ldap] About usage of name pyldap (and introducing ORM based on pyldap)
Bruno Bonfils
asyd at asyd.net
Tue Oct 4 16:21:20 EDT 2016
Hello,
I'm very close to finish and publish a basic ORM based on pyldap. I
would like to know if you're agree I publish it on pypi with the name
pyldap_orm.
For people interested, here a working example of usage of the ORM:
--8<--
# First, you must define kind of objects you want to manage:
class LDAPUser(models.LDAPModelUser):
base = 'ou=People,dc=example,dc=com'
required_attributes = ['cn']
required_objectclasses = ['inetOrgPerson']
class LDAPUsers(models.LDAPModelUsers):
children = LDAPUser
# Create a LDAPSession to connect and authenticate to the LDAP server
# Plain LDAP, LDAPs, and STARTTLS connect methods are available
session = LDAPSession(backend='ldap://localhost:1389/',
mode=LDAPSession.STARTTLS,
cert='/home/asyd/tmp/ldapclient.pem',
key='/home/asyd/tmp/ldapclient.pem')
# As well as simple_bind, and SASL_EXTERNAL (client certificate mapped)
# for authentication
session.authenticate(mode=LDAPSession.AUTH_SASL_EXTERNAL)
# You can now perform some search using LDAPModel(session).method()
user = LDAPUser(session).by_attr('uid', 'asyd')
# Attributes are available using user.<attribute>
print(user.dn)
print(user.description)
# To update an existing object, use standard python way
user.description = ['new description']
user.save()
# You can also create simple
--8<--
I also provide a mapping from bytes to str, int, boolean regarding the
attribute definition.
cheers
More information about the python-ldap
mailing list