Skip to main content

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

Metadata

Release files for ldif 4.3.0

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

Source distribution (sdist)

Source distribution for ldif 4.3.0
File Size Uploaded Provenance Actions
ldif-4.3.0.tar.gz 10.4 kB Without provenance Details for ldif-4.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 17.5 kB

Release files / ldif-4.3.0.tar.gz

Download URL ldif-4.3.0.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7758f5fa11deea9ab7574d88ce61afd7ed635f32792924cb5e75ca408648768c
BLAKE2b-256 checksum
How to use checksums
4544ff8d2308cc40d47d40daed73e3ad6d7fa536cd7c159888904541e3feacff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0rc1

Release files / ldif-4.3.0-py3-none-any.whl

Download URL ldif-4.3.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90ab5001b2587fde6573c1fc3f9659fa12d1ab24f0bdb39d7dee4a26e8bda2be
BLAKE2b-256 checksum
How to use checksums
a83f31149c06c2a5c6ded74cc3909b8799fb38de9af0d5570758a3fff3a99020
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0rc1

Security for ldif 4.3.0

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