pyconnldap


Namepyconnldap JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryA simplified Python library for LDAP connection and operations.
upload_time2025-11-02 05:18:10
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords ldap domain system connection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LDAP Connection Helper

This module provides a Python class `Connect` that simplifies connecting and interacting with an LDAP (Active Directory) server using the [`ldap3`](https://ldap3.readthedocs.io/) library.  
It supports both **simple authentication** (username/password) and **SASL GSSAPI** (Kerberos) authentication for **Linux** and **Windows** environments.

---

## 🔧 Features

- Cross-platform LDAP connection handling (Linux & Windows)
- Supports:
  - Simple bind (username + password)
  - SASL GSSAPI (Kerberos keytab or Windows domain)
- Automatically loads configuration from environment variables or `.env` file
- Provides helper methods for:
  - Searching users
  - Fetching user attributes
  - Querying accounts by custom filters
  - Returning all matching LDAP entries

---

## 📦 Dependencies

- **Python 3.10+**
- ldap3
- dotenv

---
## ⚙️ Environment Variables

You can define these in a .env file located in your home directory (~/.env on Linux, %HOMEPATH%\.env on Windows):
| Variable            | Description                     | Example                                |
| ------------------- | ------------------------------- | -------------------------------------- |
| `LDAP_HOST`         | LDAP server hostname            | `ldap.teradyne.com`                    |
| `LDAP_PORT`         | LDAP port (default: 389)        | `389`                                  |
| `LDAP_USER`         | LDAP username or principal      | `jdoe`                    |
| `LDAP_PASSWORD`     | LDAP password (for simple auth) | `MySecretPass`                         |
| `LDAP_KEYTAB`       | Path to Kerberos keytab file    | `/etc/security/jdoe.keytab`            |
| `LDAP_USER_BASE`    | Base DN for active users        | `cn=users,dc=company,dc=com`   |
| `LDAP_TERMED_BASE`  | Base DN for termed users        | `cn=termed,dc=company,dc=com`  |
| `LDAP_SRV_ACC_BASE` | Base DN for service accounts    | `cn=service,dc=company,dc=com` |

---

## 🚀 Usage Examples
### 1. Connect to LDAP
```python
from pyconnldap import Connect

# Simple bind (username/password)
conn = Connect(host='ldap.hostname.com', user='jdoe', password='MySecretPass')

# Kerberos keytab authentication
conn = Connect(host='ldap.hostname.com', user='jdoe', keytab='/etc/security/jdoe.keytab')

# If using environment variables. Make sure environment variables are loaded.
conn = Connect()
```
--- 
### 2. Search for a user in an OU
```python
found = conn.search_user(username='jdoe', ou=conn.USERS_BASE)
print(found)  # True if found, False otherwise

```
---
### 3. Get user attributes
```python
attrs = conn.get_user_attrib(username='jdoe', attrib=['mail', 'displayName'])
print(attrs)
# {'mail': ['jdoe@company.com'], 'displayName': ['John Doe']}
```
---
### 4. Search by arbitrary filter
```python
attrs = conn.get_attrib(search='mail=jdoe@company.com', attrib='cn')
print(attrs)
# {'cn': ['jdoe']}
```
---
### 5. Search all matches in an OU
```python
matches = conn.search_all_attrib(search='division=BPIT (070)', attrib='cn')
print(matches)
# [{'cn': ['User1']}, {'cn': ['User2']}, ...]
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyconnldap",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "ldap, domain system, connection",
    "author": null,
    "author_email": "Josephus <no-reply@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bb/2b/12df31dabc4ad2d1888f064a27e707ee78ff0a1fe434815e00fd122d4e3f/pyconnldap-1.0.1.tar.gz",
    "platform": null,
    "description": "# LDAP Connection Helper\r\n\r\nThis module provides a Python class `Connect` that simplifies connecting and interacting with an LDAP (Active Directory) server using the [`ldap3`](https://ldap3.readthedocs.io/) library.  \r\nIt supports both **simple authentication** (username/password) and **SASL GSSAPI** (Kerberos) authentication for **Linux** and **Windows** environments.\r\n\r\n---\r\n\r\n## \ud83d\udd27 Features\r\n\r\n- Cross-platform LDAP connection handling (Linux & Windows)\r\n- Supports:\r\n  - Simple bind (username + password)\r\n  - SASL GSSAPI (Kerberos keytab or Windows domain)\r\n- Automatically loads configuration from environment variables or `.env` file\r\n- Provides helper methods for:\r\n  - Searching users\r\n  - Fetching user attributes\r\n  - Querying accounts by custom filters\r\n  - Returning all matching LDAP entries\r\n\r\n---\r\n\r\n## \ud83d\udce6 Dependencies\r\n\r\n- **Python 3.10+**\r\n- ldap3\r\n- dotenv\r\n\r\n---\r\n## \u2699\ufe0f Environment Variables\r\n\r\nYou can define these in a .env file located in your home directory (~/.env on Linux, %HOMEPATH%\\.env on Windows):\r\n| Variable            | Description                     | Example                                |\r\n| ------------------- | ------------------------------- | -------------------------------------- |\r\n| `LDAP_HOST`         | LDAP server hostname            | `ldap.teradyne.com`                    |\r\n| `LDAP_PORT`         | LDAP port (default: 389)        | `389`                                  |\r\n| `LDAP_USER`         | LDAP username or principal      | `jdoe`                    |\r\n| `LDAP_PASSWORD`     | LDAP password (for simple auth) | `MySecretPass`                         |\r\n| `LDAP_KEYTAB`       | Path to Kerberos keytab file    | `/etc/security/jdoe.keytab`            |\r\n| `LDAP_USER_BASE`    | Base DN for active users        | `cn=users,dc=company,dc=com`   |\r\n| `LDAP_TERMED_BASE`  | Base DN for termed users        | `cn=termed,dc=company,dc=com`  |\r\n| `LDAP_SRV_ACC_BASE` | Base DN for service accounts    | `cn=service,dc=company,dc=com` |\r\n\r\n---\r\n\r\n## \ud83d\ude80 Usage Examples\r\n### 1. Connect to LDAP\r\n```python\r\nfrom pyconnldap import Connect\r\n\r\n# Simple bind (username/password)\r\nconn = Connect(host='ldap.hostname.com', user='jdoe', password='MySecretPass')\r\n\r\n# Kerberos keytab authentication\r\nconn = Connect(host='ldap.hostname.com', user='jdoe', keytab='/etc/security/jdoe.keytab')\r\n\r\n# If using environment variables. Make sure environment variables are loaded.\r\nconn = Connect()\r\n```\r\n--- \r\n### 2. Search for a user in an OU\r\n```python\r\nfound = conn.search_user(username='jdoe', ou=conn.USERS_BASE)\r\nprint(found)  # True if found, False otherwise\r\n\r\n```\r\n---\r\n### 3. Get user attributes\r\n```python\r\nattrs = conn.get_user_attrib(username='jdoe', attrib=['mail', 'displayName'])\r\nprint(attrs)\r\n# {'mail': ['jdoe@company.com'], 'displayName': ['John Doe']}\r\n```\r\n---\r\n### 4. Search by arbitrary filter\r\n```python\r\nattrs = conn.get_attrib(search='mail=jdoe@company.com', attrib='cn')\r\nprint(attrs)\r\n# {'cn': ['jdoe']}\r\n```\r\n---\r\n### 5. Search all matches in an OU\r\n```python\r\nmatches = conn.search_all_attrib(search='division=BPIT (070)', attrib='cn')\r\nprint(matches)\r\n# [{'cn': ['User1']}, {'cn': ['User2']}, ...]\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A simplified Python library for LDAP connection and operations.",
    "version": "1.0.1",
    "project_urls": null,
    "split_keywords": [
        "ldap",
        " domain system",
        " connection"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a6581f68b4651c7f3d3058d1b27cc3cc4ba282dd5009b7792f32a32147dd7f3f",
                "md5": "93bd71882af0eb77756ae70cab72f22d",
                "sha256": "5960c5c89a90a742ae7dfc9acb20467d57dcf7c3e152184da486d94e99cefdb0"
            },
            "downloads": -1,
            "filename": "pyconnldap-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "93bd71882af0eb77756ae70cab72f22d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 5722,
            "upload_time": "2025-11-02T05:18:09",
            "upload_time_iso_8601": "2025-11-02T05:18:09.194357Z",
            "url": "https://files.pythonhosted.org/packages/a6/58/1f68b4651c7f3d3058d1b27cc3cc4ba282dd5009b7792f32a32147dd7f3f/pyconnldap-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bb2b12df31dabc4ad2d1888f064a27e707ee78ff0a1fe434815e00fd122d4e3f",
                "md5": "d400e250ec6878341c5c22133a1c01be",
                "sha256": "1463e1532ad112745705d1052e4aab024fb93a171abf011125b647e14de68478"
            },
            "downloads": -1,
            "filename": "pyconnldap-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d400e250ec6878341c5c22133a1c01be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5357,
            "upload_time": "2025-11-02T05:18:10",
            "upload_time_iso_8601": "2025-11-02T05:18:10.326916Z",
            "url": "https://files.pythonhosted.org/packages/bb/2b/12df31dabc4ad2d1888f064a27e707ee78ff0a1fe434815e00fd122d4e3f/pyconnldap-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-02 05:18:10",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pyconnldap"
}
        
Elapsed time: 0.60232s