Skip to main content

lib389

lib389 is a Python library that provides a convenient way to interact with and manage a 389 Directory Server instance. It simplifies common LDAP operations and offers an object-oriented interface for various directory server components.

Installation

To install lib389 along with the main 389 Directory Server do:

pip3 install lib389==3.1.2

Important Note: When you install lib389, ensure that its version matches the version of the 389 Directory Server you plan to connect to. Mismatched versions can lead to unexpected behavior or errors.

Sample Connection Code

Here's an example of how to connect to a 389 Directory Server instance using lib389, with configuration from environment variables:

from lib389 import DirSrv
from lib389.idm.user import UserAccounts


def get_ldap_config():
    """Get LDAP configuration from environment variables."""
    return {
        'ldap_url': 'ldap://localhost:389',
        'base_dn': 'dc=example,dc=com',
        'bind_dn': 'cn=Directory Manager',
        'bind_password': 'Password123'
    }


def get_ldap_connection():
    """Create and return a connection to the LDAP server."""

    config = get_ldap_config()
    ds = DirSrv(verbose=True)
    try:
        ds.remote_simple_allocate(
            config['ldap_url'],
            config['bind_dn'],
            config['bind_password']
        )

        ds.open()
        print(f"Successfully connected to {config['ldap_url']} as {config['bind_dn']}")
        return ds

    except Exception as e:
        print(f"Failed to connect to LDAP server: {e}")
        raise


def search_users_example(basedn=None):
    """Example function to search for users and return their details as JSON."""

    config = get_ldap_config()
    search_basedn = basedn or config['base_dn']

    connection = get_ldap_connection()
    if not connection:
        print("Could not establish LDAP connection.")
        return []

    users = UserAccounts(connection, search_basedn)
    for user in users.list():
        print(user.display())

    print("Closing LDAP connection in search_users_example.")
    connection.unbind_s()


if __name__ == '__main__':
    search_users_example()

For more detailed examples on managing users, groups, services, and other directory features, please refer to the documentation within the src/lib389/doc/source/ directory, such as user.rst, group.rst, etc.

Contributing

Please see our contributing guide.

License

The 389 Directory Server is subject to the terms detailed in the license agreement file called LICENSE in the main project directory.

Metadata

Release files for lib389 3.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lib389 3.3.1
File Size Uploaded Provenance Actions
lib389-3.3.1.tar.gz 542.1 kB Without provenance Details for lib389-3.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lib389 3.3.1
File Interpreter ABI Platform Actions
lib389-3.3.1-py3-none-any.whl Python 3 none any Details for lib389-3.3.1-py3-none-any.whl

Total release size: 2.4 MB

Release files / lib389-3.3.1.tar.gz

Download URL lib389-3.3.1.tar.gz
Size 542.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f31895b991e08aa35e81bd6983093ef247630ae93914cd045a8c1972a4796551
BLAKE2b-256 checksum
How to use checksums
c09ec66729ff0899a763fde9f09a88c5f73a0e3c496eaf393f93445021519ee0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / lib389-3.3.1-py3-none-any.whl

Download URL lib389-3.3.1-py3-none-any.whl
Size 1.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
1abc293fbf95e1c2aa0df1c2874b07cbc66857297b64ab279922a94e13b5175f
BLAKE2b-256 checksum
How to use checksums
29690c87c9aef8ec955ae8f8186b2f7cc4fa9a15b39aa38c4487f3a34c866597
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for lib389 3.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page