Skip to main content

besapi

PyPI version License: MIT

besapi is a Python library that makes it easy to work with the BigFix REST API. It handles authentication, requests, and XML parsing for you, so you can focus on automating your BigFix environment instead of wrangling raw HTTP and XML.

It also includes bescli, an interactive command-line interface for exploring the REST API — great for trying things out before writing any code.

Installation

pip install besapi

Quick Start

Connect to your BigFix root server and start making requests:

import besapi

b = besapi.besapi.BESConnection(
    "my_username", "my_password", "https://rootserver.domain.org:52311"
)
rr = b.get("sites")

# Every request returns a RESTResult with several handy views of the response:
#   rr.request - the original requests object
#   rr.text    - the raw text returned by the server
#   rr.besxml  - the response as an XML string
#   rr.besobj  - the response as an lxml.objectify.ObjectifiedElement

print(rr)
<BESAPI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BESAPI.xsd">
<ExternalSite Resource="http://rootserver.domain.org:52311/api/site/external/BES%20Support">
<Name>BES Support</Name>
</ExternalSite>
<!---...--->
<CustomSite Resource="http://rootserver.domain.org:52311/api/site/custom/Org">
<Name>Org</Name>
</CustomSite>
<CustomSite Resource="http://rootserver.domain.org:52311/api/site/custom/Org%2fMac">
<Name>Org/Mac</Name>
</CustomSite>
<CustomSite Resource="http://rootserver.domain.org:52311/api/site/custom/Org%2fWindows">
<Name>Org/Windows</Name>
</CustomSite>
<CustomSite Resource="http://rootserver.domain.org:52311/api/site/custom/ContentDev">
<Name>ContentDev</Name>
</CustomSite>
<OperatorSite Resource="http://rootserver.domain.org:52311/api/site/operator/mah60">
<Name>mah60</Name>
</OperatorSite>
<ActionSite Resource="http://rootserver.domain.org:52311/api/site/master">
<Name>ActionSite</Name>
</ActionSite>
</BESAPI>

Working with results

The besobj attribute lets you navigate the XML response like a regular Python object:

>>> rr.besobj.attrib
{'{http://www.w3.org/2001/XMLSchema-instance}noNamespaceSchemaLocation': 'BESAPI.xsd'}

>>> rr.besobj.ActionSite.attrib
{'Resource': 'http://rootserver.domain.org:52311/api/site/master'}

>>> rr.besobj.ActionSite.attrib["Resource"]
'http://rootserver.domain.org:52311/api/site/master'

>>> rr.besobj.ActionSite.Name
'ActionSite'

>>> rr.besobj.OperatorSite.Name
'mah60'

>>> for cSite in rr.besobj.CustomSite:
...     print(cSite.Name)
...
Org
Org/Mac
Org/Windows
ContentDev

Downloading, uploading, and deleting content

# save a task to a file:
rr = b.get("task/operator/mah60/823975")
with open("/Users/Shared/Test.bes", "wb") as bes_file:
    bes_file.write(rr.text.encode("utf-8"))

# delete a task:
b.delete("task/operator/mah60/823975")

# create or update a task from a file:
with open("/Users/Shared/Test.bes") as bes_file:
    b.post("tasks/operator/mah60", bes_file)
    b.put("task/operator/mah60/823975", bes_file)

Looking for more? The examples folder has ready-to-run scripts for many common tasks — exporting sites, importing content, taking actions, running session relevance, and more.

Command-Line Interface

The included bescli interactive shell is the fastest way to poke around the REST API:

$ python -m bescli

BigFix> login
User [mah60]: mah60
Root Server (ex. https://server.institution.edu:52311): https://my.company.org:52311
Password:
Login Successful!
BigFix> get help
...
BigFix> get sites
...
BigFix> get sites.OperatorSite.Name
mah60
BigFix> get help/fixlets
GET:
/api/fixlets/{site}
POST:
/api/fixlets/{site}
BigFix> get fixlets/operator/mah60
...

Requirements

  • Python 3.9 or later
    • besapi 1.1.3 was the last version with partial Python 2 support
  • lxml
  • requests
  • cmd2 (for the CLI)

All dependencies are installed automatically by pip.

More Examples Using besapi

Building a Standalone Binary

You can package the CLI into a single executable with PyInstaller:

pyinstaller --clean --collect-all besapi --onefile .\src\bescli\bescli.py

Note: using UPX to compress the binary only saves about 2MB out of 16MB on Windows.

BigFix REST API Documentation

Contributing

Issues and pull requests are welcome! If you have a script built on besapi that others might find useful, consider adding it to the examples.

License

MIT License

Metadata

Release files for besapi 4.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for besapi 4.4.1
File Size Uploaded
besapi-4.4.1.tar.gz 88.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for besapi 4.4.1
File Interpreter ABI Platform
besapi-4.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 139.6 kB

Release files / besapi-4.4.1.tar.gz

Download URL besapi-4.4.1.tar.gz
Size 88.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dafef255d909b00a32ec548166c354f69855a37a96b9cd82524c49cd9d1bd4bd
BLAKE2b-256 checksum
How to use checksums
a4e5b58e5778d1080f8776129a0001b7b8bc81d4c14b3a4eb9fccd7e8f0f60b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / besapi-4.4.1-py3-none-any.whl

Download URL besapi-4.4.1-py3-none-any.whl
Size 51.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc9fdd779ca4dcfb89db91b08f94fe096219f8a7d5b5d2674828eb5a7640ab7f
BLAKE2b-256 checksum
How to use checksums
a660f9da85de0738309edddfaf6b88f27c189a4e709324b83eb4c9eb955b507f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

4.4.3

2 release files

4.4.2

2 release files

This release

4.4.1 This release

2 release files

4.3.1

2 release files

4.2.0

2 release files

4.1.5

2 release files

4.1.4

2 release files

4.1.2

2 release files

4.0.2

2 release files

4.0.1

2 release files

3.9.8

2 release files

3.9.7

2 release files

3.9.6

2 release files

3.9.5

2 release files

3.9.4

2 release files

3.9.1

2 release files

3.8.3

2 release files

3.8.2

2 release files

3.8.1

2 release files

3.7.8

2 release files

3.7.7

2 release files

3.7.6

2 release files

3.7.4

2 release files

3.7.2

2 release files

3.7.1

2 release files

3.5.1

2 release files

3.4.2

2 release files

3.4.1

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.2.6

2 release files

3.2.4

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.1.9

2 release files

3.1.8

2 release files

3.1.7

2 release files

3.1.6

2 release files

3.1.5

2 release files

3.1.4

2 release files

3.1.3

2 release files

3.1.1

2 release files

3.0.2

2 release files

3.0.1

2 release files

2.1.1

2 release files

2.0.1

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page