Python wrapper for Jamf Pro API
Project description
python-jamf
This is a Python 3 module to access the Jamf Pro classic API. The idea behind it is to have a class that maps directly to the API (https://example.com:8443/api). The API class doesn't abstract anything or hide anything from you. It simply wraps the url requests, authentication, and converts between python dictionaries and xml. It also prints json.
Requirements
This utility has been tested on macOS 10.14, macOS 10.15, macOS 11, and CentOS 7.
The python-jamf project requires python3. Please make sure you have that by running the following command.
python --version
or
python3 --version
macOS does not include python3. You can get python3 with Anaconda or Homerew. For example, this is how you install python3 with Homebrew.
brew install python3
Installation
To install python-jamf globally:
sudo pip3 install python-jamf
To install it locally for the current user:
pip3 install python-jamf --user
If you have /usr/local/bin/plistlib.py make sure it is the python 3 version.
If you don't want to install python-jamf globally you will also need to install requests first.
pip3 install requests
pip3 install python-jamf
Test
To test your install, start python3's REPL.
python3
Create an api.
import jamf
api = jamf.API()
Enter your credentials (it is only interactive if you don't have a config file--see below).
Hostname (don't forget https:// and :8443): https://example.com:8443
username: james
Password:
Then pull some data from the server and print it out.
from pprint import pprint
pprint(api.get('accounts'))
You should see something like this.
{'accounts': {'groups': None,
'users': {'user': [{'id': '2', 'name': 'james'},
{'id': '1', 'name': 'root'}]}}}
Are you exited? Try getting these as well.
pprint(api.get('computers'))
pprint(api.get('computergroups'))
pprint(api.get('policies'))
pprint(api.get('categories'))
You can view all of the things you can query by going to this url on your jamf server. https://example.com:8443/api/
Config file
The config file can be setup several ways.
First, you can download jctl and run the setconfig.py script. Please see that project for instructions.
Or you can use the JSSImporter/python-jss configuration.
If you don't want to do either of these methods, this script will also look for /Library/Preferences/com.jamfsoftware.jamf.plist and grab the server from there and just ask for username and password.
Or you can specify it in code. By specifying any of the connection settings in code, the config file will be ignored. You either have to specify hostname, username, and password, or you have to pass in promt=True to get it to prompt if you don't specify one of the required parameters (hostname, username, password).
python3
This specifies all of the credentials
import jamf
api = jamf.API(hostname='https://example.com:8443', username='james', password='secret')
Or to prompt for the password, use this.
import jamf
api = jamf.API(hostname='https://example.com:8443', username='james', prompt=True)
Note, on Linux, the config file is stored as a plist file at ~/.edu.utah.mlib.jamfutil.plist
*For further details please check out the wiki.
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
Hashes for python_jamf-0.5.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed58501410b2f460a8cfb8e9f102202101237f0c77149b53923efd7c8013747 |
|
MD5 | db2997e788ca397b0f538a178233c07a |
|
BLAKE2b-256 | d9280d433fd19d6d2ee3cbab704513618b5f15d9d220eaaa43033e6ea1787d91 |