Core API Surface
Relevant source files
The following files were used as context for generating this wiki page:
The Core API Surface of flext-target-ldif provides the primary interface for consuming Singer-formatted data and exporting it into LDAP Data Interchange Format (LDIF) files. It acts as an integration layer between the Singer protocol and the flext-ldif infrastructure, ensuring that data records are correctly transformed, validated, and serialized according to LDAP specifications.
The surface is composed of high-level facade classes, domain models for LDIF entries and files, and a specialized writer system that handles line folding, base64 encoding, and Distinguished Name (DN) generation. It supports both standard Singer Target execution and programmatic use via a service facade.
Sources: src/flext_target_ldif/target.py, src/flext_target_ldif/models.py, src/flext_target_ldif/writer.py
Main Entry Point: FlextTargetLdif
The FlextTargetLdif class is the primary orchestrator for the target operation. It manages the configuration validation, output directory setup, and the lifecycle of "Sinks"—objects responsible for handling individual data streams.
Architecture and Data Flow
The target follows a standard plugin pattern where configuration is ingested, validated against a JSON schema derived from Pydantic models, and then used to route records to stream-specific sinks.
The diagram above illustrates the flow from the CLI initialization to the final LDIF file output.
Sources: src/flext_target_ldif/target.py:22-55, src/flext_target_ldif/target.py:73-84
Data Models and Sinks
The project uses a unified model collection, FlextTargetLdifModels, which extends FlextMeltanoModels and FlextLdifModels. This ensures that all entities—such as LdifEntry and LdifFile—comply with the broader FLEXT ecosystem standards.
Core Model Components
| Component | Description |
|---|---|
| LdifFormatOptions | Configuration for line length, folding, encoding, and version headers. |
| LdifEntry | Represents a single LDAP record including DN, attributes, and object classes. |
| LdifFile | Manages a collection of entries, file paths, and metadata like size and entry count. |
| TargetLdif.Sink | The Singer-compliant processor that handles process_record and process_batch. |
Sources: src/flext_target_ldif/models.py:34-150
Sink Logic
The Sink class manages the conversion of Singer records into LDIF format. It lazily initializes a FlextTargetLdifWriter and determines the output file path based on the stream name.
The sequence diagram shows the record buffering and finalization process within the Sink.
The LDIF Writer System
The FlextTargetLdifWriter is responsible for the physical serialization of data. It implements RFC 2849 compliance, including mandatory line folding and base64 encoding for specific character sets.
Serialization Logic
- DN Generation: Uses a
dn_template(e.g.,uid={uid},ou=users,dc=example,dc=com) to format a Distinguished Name from record fields. - Attribute Mapping: Renames Singer record keys to LDAP attribute names based on
attribute_mappingconfiguration. - Encoding Checks: Automatically detects if a value starts with a space, colon, or contains non-ASCII characters, triggering base64 encoding (
::syntax). - Line Folding: Wraps lines exceeding the
line_length(default 78) by inserting a newline followed by a single space.
Sources: src/flext_target_ldif/writer.py:44-123, src/flext_target_ldif/writer.py:155-212
Writer Configuration
| Option | Type | Default | Description |
|---|---|---|---|
line_length | int | 78 | Max characters per line before folding. |
base64_encode | bool | False | If true, forces base64 encoding for all attributes. |
include_timestamps | bool | True | Adds a # Generated on: comment to the file header. |
dn_template | str | uid={uid},... | Python format string for building the DN. |
Sources: src/flext_target_ldif/writer.py:46-63
Domain Utilities
FlextTargetLdifUtilities provides static methods for specialized LDAP data handling. These are used for both internal processing and external validation.
Key Utility Functions
- build_ldif_dn: Safely populates placeholders in a template and validates the resulting DN against a regex pattern.
- format_ldif_value: Determines if a value needs base64 encoding or wrapping.
- RecordTransformer: A sub-class providing specialized normalization for
timestamp,boolean,email, andphonetypes to meet LDAP attribute syntax requirements.
Sources: src/flext_target_ldif/utilities.py:34-118, src/flext_target_ldif/utilities.py:175-235
Service Runtime Facade
For environments where the target is used as a library rather than a CLI tool, the FlextTargetLdifServiceRuntime provides a facade to wrap the domain-specific sinks into standard Singer-compliant SingerDrainSink interfaces.
# Internal creation of a sink via service runtime
runtime_sink = FlextTargetLdifModels.TargetLdif.Sink(
target_config=normalized_target_config,
stream_name=stream_name,
schema=normalized_schema,
)
Sources: src/flext_target_ldif/_utilities/service_runtime.py:58-76
The API Surface of flext-target-ldif ensures that technical complexities—such as LDAP Distinguished Name formatting, RFC-compliant line wrapping, and attribute normalization—are handled automatically during the data egress process. By leveraging the FlextTargetLdifWriter and specialized TargetLdif.Sink, it provides a robust bridge between the flexible Singer protocol and the strict requirements of LDIF file structures.