Python wrapper for Jamf Pro API
Project description
python-jamf
Programmatic Automation, Access & Control of Jamf Pro
Introduction
python-jamf
is a Python 3 module to access the Jamf Pro Classic API. The Classic API is the primary tool for programmatic access to data on a Jamf Pro server to allow integrations with other utilities or systems. The concept behind it is to have a class or simply a collection of data (variables) and methods (functions) that maps directly to the API (https://example.com:8443/api).
The python-jamf
API class doesn't hide anything from you. It handles the URL requests, authentication, and converts between XML/JSON to Python dictionaries/lists.
The python-jamf
module also provides undocumented access to Jamf Admin functionality used for uploading items to Jamf Distribution Points.
What are python-jamf
and jctl
?
Originally, it was a "patch" project that was focused on patch management including installer package management, patch management, including assigning package to patch definition, updating versions, version release branching (i.e. development, testing, production), and scripting and automation. Later, it was split into two projects, python-jamf
, which is a python library that connects to a Jamf Pro server using Jamf Pro Classic API, including keychain support for Jamf Pro credentials via keyring python project, support for PyPi to support pip installation and currently supports 56 Jamf Pro record types which will expand in number as the project continues.
The second project, jctl
, is a command-line tool that uses the python-jamf
library to select objects to create, delete, print and update. It allows performing Jamf Pro repetitive tasks quickly and provides options not available in the web GUI. It is similar to SQL statements, but far less complex. And recently added PyPi to support pip installation.
Please check out the jctl github page for more information.
Supported Jamf Records
Currently, the python-jamf
supports about 50 Jamf records like Buildings, Categories, Computers, OSXConfigurationProfiles, and Policies for example.
Each record is a singleton Python object, but they are generic and most functionality comes from the parent Record class. Objects do not have member variables for Jamf data. All Jamf Pro data is stored as a Python dictionary that is accessed with the data() method. All lists of records are singleton subclasses of the Records class.
By being singleton classes, you perform one fetch to the server for each list or record. This prevents multiple fetches for the same object. All changes you make are local until you save or refresh the object.
Note, python-jamf can work with unsupported Jamf records, it just isn't as easy as the next section shows.
Quick Example
This is just a quick example of the power and ease-of-use of python-jamf. The following code prints the last_contact_time from all computer records, from a computer record with the ID of 1, a computer record named "Jimmy's Mac", and computer records that match a regex. Then, it searches for a computer by name and if it exists then it changes the name. Lastly, it shows how to delete and create records.
import python_jamf
for computer in jamf.Computers(): # Retreive the data from the server
print(computer.data["general"]["last_contact_time"])
computers = jamf.Computers() # Use the data retrieved above, don't re-download
computers.refresh() # Re-download the records from the server
if "1" in computers:
print(computers.recordWithId(1).data['general']['last_contact_time'])
if "Jimmy's Mac" in computers:
print(computers.recordWithName("Jimmy's Mac").data['general']['last_contact_time'])
for computer in computers.recordsWithRegex("J[ia]m[myes]{2}'s? Mac"): # Matches Jimmy's, James', and James's
print(computer.data["general"]["last_contact_time"])
computer = computers.recordWithName("James's Mac)
if computer:
computer.refresh() # Re-download the record from the server
computer.data['general']['name'] = "James' Mac"
computer.save()
# Delete a record
computer = computers.recordWithName("Richard's Mac)
if computer:
computer.delete()
# Create a record (2 ways)
comp1 = computers.createNewRecord("computer1") # This really is a short-cut for the next line.
comp2 = jamf.records.Computer(0, "computer2")
A few notes. You can replace jamf.Computers()
with jamf.Policies()
or any supported record type.
Quick Start
Installing
For those that want to try python-jamf
quickly here are some general steps:
- Install Module & Requirements:
sudo pip3 install python-jamf
- Create an Jamf Pro API User
- Enter hostname, username, and password
- Test:
conf-python-jamf -t
Uninstalling
Uninstalling python-jamf
is easy if you installed it via pip
. pip
is the Package Installer for Python.
To uninstall python-jamf
run the following command:
sudo pip3 uninstall python-jamf
Upgrading
Upgrading python-jamf
is easy if you installed it via pip
. pip
is the Package Installer for Python.
To upgrade python-jamf
run the following command:
sudo pip3 install --upgrade python-jamf
Getting Help
Wiki
More Documentation
For further in-depth details please check out the wiki.
Searching the wiki
To search this wiki use the "Search" field in the GitHub navigation bar above. Then on the search results page select the "Wiki" option or click here and search.
MacAdmin Slack Channel
If you have additional questions, or need more help getting started, post a question on the MacAdmin's Slack jctl channel.
Latest Status
Releases
Please see the Changelog for all release notes.
Thank you yairf-s1 and pythoninthegrass for your contributions.
See python-jamf
upgrade documentation to upgrade to latest release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python-jamf-0.9.9.tar.gz
.
File metadata
- Download URL: python-jamf-0.9.9.tar.gz
- Upload date:
- Size: 44.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64d06610997699c07cbe1754a1d6f562c506b02ef24f7027f87de872e2b21048 |
|
MD5 | d2f981b23212780048dba4184a2874b8 |
|
BLAKE2b-256 | eb8d0646280c4415affd3ed4822a4f7f41365064eb2b810f59c8643c1c7bcdd8 |
File details
Details for the file python_jamf-0.9.9-py3-none-any.whl
.
File metadata
- Download URL: python_jamf-0.9.9-py3-none-any.whl
- Upload date:
- Size: 46.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb0952101209e91f539ce2f62f89b61c58818171af91194429978d0119031058 |
|
MD5 | b5bce34e6d2b9395d5d6d83e20bf88dd |
|
BLAKE2b-256 | f23c6625e9022120c7838670c434ecfe22ffb23f7027b8199b239a27f3ff6078 |