Skip to main content

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


Download files

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

Source Distribution

python-jamf-0.5.6.tar.gz (103.9 kB view hashes)

Uploaded Source

Built Distribution

python_jamf-0.5.6-py3-none-any.whl (113.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page