Synchronous API¶
In addition to the asynchronous interface, the same LDAP client API can be used in a synchronous (blocking) manner. This is useful for scripts, utilities, or environments where asynchronous execution is not required or where blocking I/O is acceptable.
The synchronous API mirrors the asynchronous one, allowing you to reuse the same method calls and code structure without modification – only the event loop integration changes.
The following example demonstrates how to perform the same operations using synchronous calls.
The API is also available for synchronous IO blocking operations¶
from freeiam import ldap
from freeiam.ldap.constants import Scope
def ldap_synchronous_examples():
"""
Yes, you can do all this also synchronously!
Just enter the synchronous context manager.
"""
with ldap.Connection('ldap://localhost:389') as conn:
conn.bind('cn=admin,dc=freeiam,dc=org', 'iamfree')
search_base = 'dc=freeiam,dc=org'
# search for DN and attrs
for entry in conn.search(
search_base, Scope.SUBTREE, '(&(uid=*)(objectClass=person))'
):
print(entry.dn, entry.attr)
... # take a look at the API docs or other examples!