Skip to main content

An Object-Oriented Active Directory management framework built on ADSI

Project description


pyad is a python library designed to provide a simple, object oriented interface to Active Directory through ADSI on the Windows platform. pyad requires pywin32, available at

pyad is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A copy of the GNU General Public License is available at <>.


Active Directory objects are represented by standard python objects. There are classes for all major types of Active Directory objects: ADComputer, ADContainer, ADDomain, ADGroup, ADUser, all of which inherit from ADObject. It is possible to connect to objects via CN, DN, and GUID. Example:

import pyad
u = pyad.aduser.ADUser.from_cn("user1")
c = pyad.adcomputer.ADComputer.from_dn("cn=WS1,ou=Workstations,dc=domain,dc=com")
g = pyad.adgroup.ADGroup.from_cn("group1")

It is possible to read attribute values in two ways.

print u.displayName
print u.get_attribute("displayName")

Attributes can be set by calling clear_attribute, update_attribute, update_attributes, append_to_attribute, and remove_from_attribute. Example:

u.update_attribute("displayName", "new value")

There are other helper methods available for managing attributes. We provide further examples below for common actions for each object type.

Group Examples

1. Finding group members:

for object in g.get_members(recursive=False):
print object

2. Adding an object to a group:


3. Set group scope:


User Examples

1. Set password:


2. Force password change on login:


Container Examples

1. Find all objects in an OU:

ou = pyad.adcontainer.ADContainer.from_dn("OU=Workstations,DC=company,DC=com")
for obj in ou.get_children():
print obj

2. Recursively find all computers below a certain OU:

for c in ou.get_children(recursive=True, filter=[pyad.adcomputer.ADComputer]):
print c

Creating Objects

It is possible to create objects through pyad. Example:

ou = pyad.adcontainer.ADContainer.from_dn("OU=Workstations,DC=company,DC=com")
c = pyad.adcomputer.ADComputer.create(
name = 'myworkstation2',
container_object = ou,
enable = True,
optional_attributes = dict(
description = "newly created computer"


It is also possible to make queries to find objects. Example:

q = pyad.adquery.ADQuery()
attributes = ['distinguishedname', 'description'],
where_clause = "cn like 'ws%'",
base_dn = "dc=company,dc=com"
for r in q.get_results():
print r['distinguishedname']

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyad, version 0.4.9
Filename, size File type Python version Upload date Hashes
Filename, size pyad-0.4.9-py2.7.egg (44.5 kB) File type Egg Python version any Upload date Hashes View
Filename, size pyad.0.4.9.tar.gz (253.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page