ldap3.abstract package

Submodules

ldap3.abstract.attrDef module

class ldap3.abstract.attrDef.AttrDef(name, key=None, validate=None, pre_query=None, post_query=None, default=NotImplemented, dereference_dn=None, description=None, mandatory=False, single_value=None, alias=None)[source]

Bases: object

Hold the definition of an attribute

Parameters:
  • name (string) – the real attribute name
  • key (string) – the friendly name to use in queries and when accessing the attribute, default to the real attribute name
  • validate (callable) – called to check if the value in the query is valid, the callable is called with the value parameter
  • pre_query (callable) – called to transform values returned by search
  • post_query (callable) – called to transform values returned by search
  • default (string, integer) – value returned when the attribute is absent (defaults to NotImplemented to allow use of None as default)
  • dereference_dn (ObjectDef) – reference to an ObjectDef instance. When the attribute value contains a dn it will be searched and substituted in the entry
  • description (string) – custom attribute description
  • mandatory (boolean) – specify if attribute is defined as mandatory in LDAP schema

ldap3.abstract.attribute module

class ldap3.abstract.attribute.Attribute(attr_def, entry, cursor)[source]

Bases: object

Attribute/values object, it includes the search result (after post_query transformation) of each attribute in an entry

Attribute object is read only

  • values: contain the processed attribute values
  • raw_values’: contain the unprocessed attribute values
value
Returns:The single value or a list of values of the attribute.
class ldap3.abstract.attribute.OperationalAttribute(attr_def, entry, cursor)[source]

Bases: ldap3.abstract.attribute.Attribute

Operational attribute/values object. Include the search result of an operational attribute in an entry

OperationalAttribute object is read only

  • values: contains the processed attribute values
  • raw_values: contains the unprocessed attribute values

It may not have an AttrDef

class ldap3.abstract.attribute.WritableAttribute(attr_def, entry, cursor)[source]

Bases: ldap3.abstract.attribute.Attribute

add(values)[source]
changes
delete(values)[source]
discard()[source]
remove()[source]
set(values)[source]
virtual

ldap3.abstract.cursor module

class ldap3.abstract.cursor.Cursor(connection, object_def, get_operational_attributes=False, attributes=None, controls=None, auxiliary_class=None)[source]

Bases: object

errors
failed
match(attributes, value)[source]

Return entries with text in one of the specified attributes

match_dn(dn)[source]

Return entries with text in DN

operations
remove(entry)[source]
class ldap3.abstract.cursor.Operation(request, result, response)

Bases: tuple

request

Alias for field number 0

response

Alias for field number 2

result

Alias for field number 1

class ldap3.abstract.cursor.Reader(connection, object_def, base, query='', components_in_and=True, sub_tree=True, get_operational_attributes=False, attributes=None, controls=None, auxiliary_class=None)[source]

Bases: ldap3.abstract.cursor.Cursor

Reader object to perform searches:

Parameters:
  • connection (LDAPConnection) – the LDAP connection object to use
  • object_def (ObjectDef) – the ObjectDef of the LDAP object returned
  • query (str) – the simplified query (will be transformed in an LDAP filter)
  • base (str) – starting base of the search
  • components_in_and (bool) – specify if assertions in the query must all be satisfied or not (AND/OR)
  • sub_tree (bool) – specify if the search must be performed ad Single Level (False) or Whole SubTree (True)
  • get_operational_attributes (bool) – specify if operational attributes are returned or not
  • controls (tuple) – controls to be used in search
attribute_class

alias of Attribute

clear()[source]

Clear the Reader search parameters

components_in_and
entry_class

alias of Entry

entry_initial_status = 'Read'
query
reset()[source]

Clear all the Reader parameters

search(attributes=None)[source]

Perform the LDAP search

Returns:Entries found in search
search_level(attributes=None)[source]

Perform the LDAP search operation with SINGLE_LEVEL scope

Returns:Entries found in search
search_object(entry_dn=None, attributes=None)[source]

Perform the LDAP search operation SINGLE_OBJECT scope

Returns:Entry found in search
search_paged(paged_size, paged_criticality=True, generator=True, attributes=None)[source]

Perform a paged search, can be called as an Iterator

Parameters:
  • attributes – optional attributes to search
  • paged_size (int) – number of entries returned in each search
  • paged_criticality (bool) – specify if server must not execute the search if it is not capable of paging searches
  • generator (bool) – if True the paged searches are executed while generating the entries, if False all the paged searches are execute before returning the generator
Returns:

Entries found in search

search_subtree(attributes=None)[source]

Perform the LDAP search operation WHOLE_SUBTREE scope

Returns:Entries found in search
class ldap3.abstract.cursor.Writer(connection, object_def, get_operational_attributes=False, attributes=None, controls=None, auxiliary_class=None)[source]

Bases: ldap3.abstract.cursor.Cursor

attribute_class

alias of WritableAttribute

commit(refresh=True)[source]
discard()[source]
entry_class

alias of WritableEntry

entry_initial_status = 'Writable'
static from_cursor(cursor, connection=None, object_def=None, custom_validator=None)[source]
static from_response(connection, object_def, response=None)[source]
new(dn)[source]
refresh_entry(entry, tries=4, seconds=2)[source]

ldap3.abstract.entry module

class ldap3.abstract.entry.Entry(dn, cursor)[source]

Bases: ldap3.abstract.entry.EntryBase

The Entry object contains a single LDAP entry. Attributes can be accessed either by sequence, by assignment or as dictionary keys. Keys are not case sensitive.

The Entry object is read only

  • The DN is retrieved by entry_dn
  • The Reader reference is in _cursor()
  • Raw attributes values are retrieved by the _ra_attributes and _raw_attribute() methods
entry_writable(object_def=None, writer_cursor=None, attributes=None, custom_validator=None, auxiliary_class=None)[source]
class ldap3.abstract.entry.EntryBase(dn, cursor)[source]

Bases: object

The Entry object contains a single LDAP entry. Attributes can be accessed either by sequence, by assignment or as dictionary keys. Keys are not case sensitive.

The Entry object is read only

  • The DN is retrieved by entry_dn
  • The cursor reference is in _cursor
  • Raw attributes values are retrieved with _raw_attributes and the _raw_attribute() methods
entry_attributes
entry_attributes_as_dict
entry_cursor
entry_definition
entry_dn
entry_mandatory_attributes
entry_raw_attribute(name)[source]
Parameters:name – name of the attribute
Returns:raw (unencoded) value of the attribute, None if attribute is not found
entry_raw_attributes
entry_read_time
entry_status
entry_to_json(raw=False, indent=4, sort=True, stream=None, checked_attributes=True, include_empty=True)[source]
entry_to_ldif(all_base64=False, line_separator=None, sort_order=None, stream=None)[source]
class ldap3.abstract.entry.EntryState(dn, cursor)[source]

Bases: object

Contains data on the status of the entry. Does not pollute the Entry __dict__.

set_status(status)[source]
class ldap3.abstract.entry.WritableEntry(dn, cursor)[source]

Bases: ldap3.abstract.entry.EntryBase

entry_changes
entry_commit_changes(refresh=True, controls=None, clear_history=True)[source]
entry_delete()[source]
entry_discard_changes()[source]
entry_move(destination_dn)[source]
entry_refresh(tries=4, seconds=2)[source]

Refreshes the entry from the LDAP Server

entry_rename(new_name)[source]
entry_virtual_attributes

ldap3.abstract.objectDef module

class ldap3.abstract.objectDef.ObjectDef(object_class=None, schema=None, custom_validator=None, auxiliary_class=None)[source]

Bases: object

Represent an object in the LDAP server. AttrDefs are stored in a dictionary; the key is the friendly name defined in AttrDef.

AttrDefs can be added and removed using the += and -= operators

ObjectDef can be accessed either as a sequence and a dictionary. When accessed the whole AttrDef instance is returned

add_attribute(definition=None)[source]

Add an AttrDef to the ObjectDef. Can be called with the += operator. :param definition: the AttrDef object to add, can also be a string containing the name of attribute to add. Can be a list of both

add_from_schema(attribute_name, mandatory=False)[source]
clear_attributes()[source]

Empty the ObjectDef attribute list

remove_attribute(item)[source]

Remove an AttrDef from the ObjectDef. Can be called with the -= operator. :param item: the AttrDef to remove, can also be a string containing the name of attribute to remove

Module contents