LDIF

LDIF is a simple Elixir parser for LDAP Data Interchange Format (LDIF) text files. It will convert the entries within them to Elixir structs, and can directly apply LDIF change records to normal LDIF records.

RFC 2849 describes LDIF as:

... a file format suitable for describing directory information or modifications made to directory information. The file format, known as LDIF, for LDAP Data Interchange Format, is typically used to import and export directory information between LDAP-based directory servers, or to describe a set of changes which are to be applied to a directory.

The LDIF format is commonly used for importing records and changes into LDAP directories such as OpenLDAP. Records are typically for contact details, user accounts, groups and departments but can be for any information.

Here is an example LDIF record:

dn:cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com
objectclass:top
objectclass:person
objectclass:organizationalPerson
cn:Barbara Jensen
cn:Barbara J Jensen
cn:Babs Jensen
sn:Jensen
uid:bjensen
telephonenumber:+1 408 555 1212
description:Babs is a big sailing fan, and travels extensively in sea
 rch of perfect sailing conditions.
title:Product Manager, Rod and Reel Division

Hex pmAPI DocsGithub Elixir CI

Run in Livebook

Features

Caveats

Examples

Importing an LDIF of directory entries

ldif = File.read!("test/support/rfc_jensen_entries.ldif")

LDIF.decode_entries!(ldif)
|> List.first()
#=> %LDIF.Entry{dn: "ou=Product Development, dc=airius, dc=com", attributes: %{"objectClass" => ["top", "organizationalUnit"],"ou" => ["Product Development"]}}

Using a sigil to parse LDIF, then reading an attribute


    require LDIF.Sigil

    ~L"""
    dn:cn=Barbara Jensen, ou=Product Development, dc=airius, dc=com
    objectclass:top
    objectclass:person
    objectclass:organizationalPerson
    cn:Barbara Jensen
    cn:Barbara J Jensen
    cn:Babs Jensen
    sn:Jensen
    uid:bjensen
    telephonenumber:+1 408 555 1212
    description:Babs is a big sailing fan, and travels extensively in sea
      rch of perfect sailing conditions.
    title:Product Manager, Rod and Reel Division
    """
    |> List.first()
    |> LDIF.Entry.attribute("cn")
    #=> ["Barbara Jensen", "Barbara J Jensen", "Babs Jensen"]

Applying changes to a list of entries

entries = File.read!("test/support/rfc_jensen_entries.ldif")
          |> LDIF.decode_entries!(ldif)

changes = File.read!("test/support/rfc_jensen_changes.ldif")
          |> LDIF.decode_changes!(ldif)

LDIF.apply_changes!(changes, entries)

Installation

If available in Hex, the package can be installed by adding LDIF to your list of dependencies in mix.exs:

def deps do
  [
    {:ldif, "~> 0.1.0"}
  ]
end

References

LDIF Resources

Documentation

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ldif.

Contributing

You can request new features by creating an issue, or submit a pull request with your contribution.

If you are comfortable working with Python but this package's Elixir code is unfamiliar then this blog post may help: Elixir For Humans Who Know Python

This software was produced without generative AI and no contributions from generative AI will be accepted.

Copyright and License

Copyright (c) 2026 Digital Identity Ltd, UK

This software is MIT licensed.

Disclaimer

This software may change considerably in the first few releases after 0.1.0 - it is not yet stable!