anyldap is a pure-Python, AnyIO-based library for Python 3.10 and newer that implements:
LDAP client and server logic
a client with python-ldap’s API, awaited rather than blocking
separately-accessible LDAP and BER protocol message generation/parsing
ASCII-format LDAP filter generation and parsing
LDIF format data generation
Samba password changing logic
Also included is a set of LDAP utilities for use from the command line.
The full documentation is available on Read the Docs.
Quick Usage Example
import anyio
from anyldap.protocols.ldap import ldapclient, ldapconnector, ldapsyntax
async def example():
serverip = "192.168.128.21"
basedn = b"dc=example,dc=com"
binddn = b"bjensen@example.com"
bindpw = b"secret"
query = b"(cn=Babs*)"
overrides = {basedn: (serverip, 389)}
connection = await ldapconnector.connectToLDAPDNAsync(
basedn,
ldapclient.LDAPClient,
overrides=overrides,
)
async with connection as client:
await client.bind_async(binddn, bindpw)
entry = ldapsyntax.LDAPEntry(client, basedn)
results = await entry.search_async(filterText=query)
for result in results:
print(result.getLDIF())
if __name__ == "__main__":
anyio.run(example)
python-ldap’s API but async
anyldap.ldap is python-ldap’s ldap module made async: the names, the arguments they take and the values they hand back are python-ldap’s, with every operation a coroutine, so code written against it ports by adding await. It runs on asyncio and on trio, since it is written against AnyIO, and none of it is a binding to OpenLDAP’s C library – the protocol, the SASL mechanisms and the TLS handshake are anyldap’s own, which is also why the handful of things only libldap can answer are not here:
import anyio
from anyldap import ldap
async def example():
async with ldap.initialize("ldap://ldap.example.com") as connection:
await connection.simple_bind_s("bjensen@example.com", b"secret")
results = await connection.search_s(
"dc=example,dc=com", ldap.SCOPE_SUBTREE, "(cn=Babs*)"
)
for dn, attributes in results:
print(dn, attributes)
if __name__ == "__main__":
anyio.run(example)
ldap.controls, ldap.schema, ldap.sasl, ldap.dn, ldap.filter, ldap.modlist, ldap.cidict, ldap.ldapurl, ldap.ldif, ldap.asyncsearch, ldap.syncrepl and ReconnectLDAPObject are here too. What it does and does not cover is in the documentation. Most of python-ldap’s own test suite is ported under interop/, next to tests that run the same operations through both libraries against one OpenLDAP server and compare the answers; tox -e interop runs them.
Installation
Install anyldap from PyPI:
python -m pip install anyldap
To install a repository checkout in editable mode:
python -m pip install -e .
For a server example from a repo checkout, see docs/source/examples/quickstart_server.py.
Dependencies:
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anyldap-0.2.0.tar.gz.
File metadata
- Download URL: anyldap-0.2.0.tar.gz
- Upload date:
- Size: 473.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ea561dd5384ce552fa4d41d54975e5565d6a3419a090bac7b4ad3474f9db7e9
|
|
| MD5 |
e8c8a8a67d282760e887eabeba4b2543
|
|
| BLAKE2b-256 |
9da168f9f04c3b76c528738224d3449eb5be29a01720a407782cca615ded012b
|
Provenance
The following attestation bundles were made for anyldap-0.2.0.tar.gz:
Publisher:
main.yml on graingert/anyldap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anyldap-0.2.0.tar.gz -
Subject digest:
9ea561dd5384ce552fa4d41d54975e5565d6a3419a090bac7b4ad3474f9db7e9 - Sigstore transparency entry: 2343210240
- Sigstore integration time:
-
Permalink:
graingert/anyldap@05a902f88496dafda2ded7e4601b8dd83b529d3c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/graingert
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@05a902f88496dafda2ded7e4601b8dd83b529d3c -
Trigger Event:
push
-
Statement type:
File details
Details for the file anyldap-0.2.0-py3-none-any.whl.
File metadata
- Download URL: anyldap-0.2.0-py3-none-any.whl
- Upload date:
- Size: 213.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8fc93e1796fb3d7eb009201ce1a0ac306d26b9231ee3d05230a44f0748eee68
|
|
| MD5 |
aa0cd20265414275c72b46ebbf2ad79e
|
|
| BLAKE2b-256 |
9e62d3354b310f9e20f963a27134f63e56f119b5fa6aacfcfe78dee1aef7c1f7
|
Provenance
The following attestation bundles were made for anyldap-0.2.0-py3-none-any.whl:
Publisher:
main.yml on graingert/anyldap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
anyldap-0.2.0-py3-none-any.whl -
Subject digest:
c8fc93e1796fb3d7eb009201ce1a0ac306d26b9231ee3d05230a44f0748eee68 - Sigstore transparency entry: 2343210262
- Sigstore integration time:
-
Permalink:
graingert/anyldap@05a902f88496dafda2ded7e4601b8dd83b529d3c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/graingert
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@05a902f88496dafda2ded7e4601b8dd83b529d3c -
Trigger Event:
push
-
Statement type: