Skip to main content

generate and parse LDIF data (see RFC 2849).

Project description

ldif - parse and generate LDIF data (see RFC 2849).

Commit activity Code size in bytes License Latest version PyPI Downloads

This is a fork of the ldif module from python-ldap with python3/unicode support.

One of its benefits is that it's a pure-python package (you don't depend on the libldap2-dev (or similar) package that needs to be installed on your laptop / test machine / production server).

See the last entry in changelog for a more complete list of differences.

This package only support Python 3 (>= 3.7, actually).

Usage

Parse LDIF from a file (or BytesIO):

from ldif import LDIFParser
from pprint import pprint

parser = LDIFParser(open("data.ldif", "rb"))
for dn, record in parser.parse():
    print('got entry record: %s' % dn)
    pprint(record)

Write LDIF to a file (or BytesIO):

from ldif import LDIFWriter

writer = LDIFWriter(open("data.ldif", "wb"))
writer.unparse("mail=alice@example.com", {
    "cn": ["Alice Alison"],
    "mail": ["alice@example.com"],
    "objectclass": ["top", "person"],
})

Unicode support

The stream object that is passed to parser or writer must be an ascii byte stream.

The spec allows to include arbitrary data in base64 encoding or via URL. There is no way of knowing the encoding of this data. To handle this, there are two modes:

By default, the LDIFParser will try to interpret all values as UTF-8 and leave only the ones that fail to decode as bytes. But you can also pass an encoding of None to the constructor, in which case the parser will not try to do any conversion and return bytes directly.

Changelog

See here

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

ldif-4.3.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

ldif-4.3.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ldif-4.3.0.tar.gz.

File metadata

  • Download URL: ldif-4.3.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc1

File hashes

Hashes for ldif-4.3.0.tar.gz
Algorithm Hash digest
SHA256 7758f5fa11deea9ab7574d88ce61afd7ed635f32792924cb5e75ca408648768c
MD5 8214ee189e4391016a7ba2f0e42fe59f
BLAKE2b-256 4544ff8d2308cc40d47d40daed73e3ad6d7fa536cd7c159888904541e3feacff

See more details on using hashes here.

File details

Details for the file ldif-4.3.0-py3-none-any.whl.

File metadata

  • Download URL: ldif-4.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0rc1

File hashes

Hashes for ldif-4.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90ab5001b2587fde6573c1fc3f9659fa12d1ab24f0bdb39d7dee4a26e8bda2be
MD5 36068b51f4de7cc3ffec8d80b539dcd0
BLAKE2b-256 a83f31149c06c2a5c6ded74cc3909b8799fb38de9af0d5570758a3fff3a99020

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