- To build pythonldap3wrapper from source, first clone the repo
git clone [email protected]:tjobarow/pythonldap3wrapper.git
- Create a new python virtual environment (if you have that module installed in python)
python -m venv .my-venv
- Activate the environment (depends on OS)
- Linux/MacOS:
source ./.my-venv/bin/activate
- Windows (PowerShell|CMD prompt)
./.my-venv/Scripts/[Activate.ps1|Activate.bat]
- Install buildtools & wheel
pip install build wheel
- Build package from within cloned repo
python -m build --wheels
- Install pythonldap3wrapper using pip from within root directory of pythonldap3wrapper
pip install .
from ldap3_wrapper import Ldap3Wrapper
Create an instance of pythonldap3wrapper, providing the following parameters. Can be pulled from environment variables, or however you see fit.
ldap = Ldap3Wrapper(
ldap_server_host=os.getenv("bind_hostname"),
bind_cn=os.getenv("bind_cn"),
bind_username=os.getenv("bind_username"),
bind_password=os.getenv("bind_password"),
use_ldaps=True,
)
This seaches by a full or partial email. This appends a wildcard to the end of the provided string, and matches on mail
LDAP attribute.
user=ldap.search_user_by_email(user_email="tjobarow")
This seaches by a full or partial sAMAccountName. This appends a wildcard to the end of the provided string, and matches on sAMAccountName
LDAP attribute.
user=ldap.search_user_by_userid(user_id="tjSamName")