| 1 |
Bonsai |
| 2 |
====== |
| 3 |
|
| 4 |
.. image:: https://img.shields.io/pypi/v/bonsai.svg?style=flat-square |
| 5 |
:target: https://pypi.python.org/pypi/bonsai/ |
| 6 |
:alt: PyPI Version |
| 7 |
|
| 8 |
.. image:: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fnoirello%2Fbonsai%2Fbadge%3Fref%3Ddev&style=flat-square |
| 9 |
:target: https://actions-badge.atrox.dev/noirello/bonsai/goto?ref=dev |
| 10 |
:alt: GitHub Action Build Status |
| 11 |
|
| 12 |
.. image:: https://dev.azure.com/noirello/bonsai/_apis/build/status/noirello.bonsai?branchName=dev |
| 13 |
:target: https://dev.azure.com/noirello/bonsai/_build |
| 14 |
:alt: Azure Pipelines Status |
| 15 |
|
| 16 |
.. image:: https://img.shields.io/appveyor/ci/noirello/bonsai/dev.svg?style=flat-square |
| 17 |
:target: https://ci.appveyor.com/project/noirello/bonsai |
| 18 |
:alt: AppVeyor CI Build Status |
| 19 |
|
| 20 |
.. image:: https://codecov.io/gh/noirello/bonsai/branch/dev/graph/badge.svg?token=gPAMdWATgj |
| 21 |
:target: https://app.codecov.io/gh/noirello/bonsai/tree/dev/src |
| 22 |
:alt: Coverage Status |
| 23 |
|
| 24 |
.. image:: https://readthedocs.org/projects/bonsai/badge/?version=latest&style=flat-square |
| 25 |
:target: http://bonsai.readthedocs.org/en/latest/ |
| 26 |
:alt: Documentation Status |
| 27 |
|
| 28 |
.. image:: https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square |
| 29 |
:target: https://raw.githubusercontent.com/noirello/bonsai/master/LICENSE |
| 30 |
:alt: GitHub License |
| 31 |
|
| 32 |
This is a module for handling LDAP operations in Python. Uses libldap2 on Unix platforms and |
| 33 |
WinLDAP on Microsoft Windows. LDAP entries are mapped to a special Python case-insensitive |
| 34 |
dictionary, tracking the changes of the dictionary to modify the entry on the server easily. |
| 35 |
|
| 36 |
Supports only Python 3.7 or newer, and LDAPv3. |
| 37 |
|
| 38 |
Features |
| 39 |
-------- |
| 40 |
|
| 41 |
- Uses LDAP libraries (OpenLDAP and WinLDAP) written in C for faster |
| 42 |
processing. |
| 43 |
- Simple pythonic design. |
| 44 |
- Implements an own dictionary-like object for mapping LDAP entries |
| 45 |
that makes easier to add and modify them. |
| 46 |
- Works with various asynchronous library (like asyncio, gevent). |
| 47 |
|
| 48 |
Requirements for building |
| 49 |
------------------------- |
| 50 |
|
| 51 |
- python3.7-dev or newer |
| 52 |
- libldap2-dev |
| 53 |
- libsasl2-dev |
| 54 |
- libkrb5-dev or heimdal-dev (optional) |
| 55 |
|
| 56 |
Documentation |
| 57 |
------------- |
| 58 |
|
| 59 |
Documentation is available `online`_ with a simple tutorial. |
| 60 |
|
| 61 |
Example |
| 62 |
------- |
| 63 |
|
| 64 |
Simple search and modify: |
| 65 |
|
| 66 |
.. code:: python |
| 67 |
|
| 68 |
import bonsai |
| 69 |
|
| 70 |
client = bonsai.LDAPClient("ldap://localhost") |
| 71 |
client.set_credentials("SIMPLE", user="cn=admin,dc=bonsai,dc=test", password="secret") |
| 72 |
with client.connect() as conn: |
| 73 |
res = conn.search("ou=nerdherd,dc=bonsai,dc=test", 2, "(cn=chuck)") |
| 74 |
res[0]['givenname'] = "Charles" |
| 75 |
res[0]['sn'] = "Carmichael" |
| 76 |
res[0].modify() |
| 77 |
|
| 78 |
Using with asyncio: |
| 79 |
|
| 80 |
.. code:: python3 |
| 81 |
|
| 82 |
import asyncio |
| 83 |
import bonsai |
| 84 |
|
| 85 |
async def do(): |
| 86 |
client = bonsai.LDAPClient("ldap://localhost") |
| 87 |
client.set_credentials("DIGEST-MD5", user="admin", password="secret") |
| 88 |
async with client.connect(is_async=True) as conn: |
| 89 |
res = await conn.search("ou=nerdherd,dc=bonsai,dc=test", 2) |
| 90 |
print(res) |
| 91 |
who = await conn.whoami() |
| 92 |
print(who) |
| 93 |
|
| 94 |
asyncio.run(do()) |
| 95 |
|
| 96 |
Changelog |
| 97 |
--------- |
| 98 |
|
| 99 |
The changelog is available `here`_ and included in the documentation as well. |
| 100 |
|
| 101 |
Contribution |
| 102 |
------------ |
| 103 |
|
| 104 |
Any contributions and advices are welcome. Please report any issues at |
| 105 |
the `GitHub page`_. |
| 106 |
|
| 107 |
.. _online: http://bonsai.readthedocs.org/en/latest/ |
| 108 |
.. _here: https://github.com/noirello/bonsai/blob/master/CHANGELOG.rst |
| 109 |
.. _GitHub page: https://github.com/noirello/bonsai/issues |