Skip to main content

A library for accessing, testing, and configuring the 389 Directory Server

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lib389-3.2.0.tar.gz (513.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lib389-3.2.0-py3-none-any.whl (1.7 MB view details)

Uploaded Python 3

File details

Details for the file lib389-3.2.0.tar.gz.

File metadata

  • Download URL: lib389-3.2.0.tar.gz
  • Upload date:
  • Size: 513.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for lib389-3.2.0.tar.gz
Algorithm Hash digest
SHA256 a2a8c3d2f98b8e175914a7272c54f5fba0ce80327a03389e4677d2e9de4e9711
MD5 221120562916b0ee92576ce9da69e4d8
BLAKE2b-256 1c34394f6dd7383e5efc37cbd52c9180d42f69d70f0f6c0e6b248a2020842e48

See more details on using hashes here.

File details

Details for the file lib389-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: lib389-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for lib389-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59d3fbb2d0952801784d5660e090d995ef90f28670a20dca54b4b3e481cb3a39
MD5 a329bec9deae61a01772ec7a358dbe57
BLAKE2b-256 f7a5aad08b0d3e9ebdd2164cbc7887a5e5cf1e332d6d2132968eb4554d54bd89

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page