Skip to main content

Britive Python SDK

Pure Python implementation for interacting with the Britive API.

This package aims to wrap the Britive API for usage in Python development. For the most part it is a simple wrapper (sending potentially bad parameters to the API) but there are a couple of places where liberties were taken to enhance the developer/end user experience. Some APIs may also be combined into one Python method with a parameter if and where it makes more sense to present the API that way.

This package supports Python versions >= 3.10.

Installation

pip install britive

Or execute one of the following commands if you wish to pull directly from the Github repo instead of PyPi. Or navigate to Releases and use the URL of the tarball release that is needed, if not the lastest.

pip install $(curl -s https://api.github.com/repos/britive/python-sdk/releases/latest \
    | jq -r '.assets[] | select(.content_type == "application/x-gzip") | .browser_download_url')

OR

pip install $(curl -s https://api.github.com/repos/britive/python-sdk/releases/latest \
    | grep "browser_download_url.*.tar.gz" | cut -d : -f 2,3 | tr -d \")

Documentation

Each public method is documented with a docstring which provides details on what the method does, the parameters the method accepts, and details about what is returned from the method.

Official API documentation can be found here: Britive API Documentation.

Authentication

Authentication is handled solely via API tokens. The token must be provided in one of two methods.

  1. Passed directly into the class constructor.
  2. Injected as an environment variable into the execution context where this package is being run.
    1. The environment variable name must be BRITIVE_API_TOKEN.

As of v2.5.0 a Bearer token can be provided as well. A Bearer token is generated as part of an interactive login process and is temporary in nature. This is to support the Britive Python CLI.

All Britive API tokens are authenticated against a specific Britive tenant. The name of the tenant must be presented in one of two methods.

  1. Passed directly into the Britive class constructor.
  2. Injected as an environment variable into the execution context where this package is being run.
    1. The environment variable name must be BRITIVE_TENANT.

In order to obtain the tenant name, reference the Britive URL used to log into the UI. If the URL is https://example.britive-app.com then the tenant name will be example.

Pagination

All pagination is handled by the package. The caller will never have to deal with paginated responses.

Assumptions

  • The caller has access to an active Britive tenant.
  • The caller has been granted an API token and/or has the ability to generate an API token.
    • This can be either for a User or Service Identity.
  • No assumptions are made about the operating system or file system.
    • Nothing is persisted to disk.
      • The end user must persist responses to disk if and when that is required.

Resource Coverage

The following Britive resources are supported with full CRUDL operations where appropriate, and additional actions where they exist.

  • Access Broker
  • Access Builder
  • Accounts
  • Accounts (associated with an application/environment)
  • API Tokens (for Users)
  • Applications
  • Audit Logs
  • Environment
  • Environment Groups
  • Groups (associated with an application/environment)
  • Identity Attributes
  • Identity Providers
  • My Access (access granted to the given identity (user or service))
  • My Approvals
  • My Requests
  • My Resources (access granted to the given identity (user or service))
  • My Secrets (access granted to the given identity (user or service))
  • Notifications
  • Permissions (associated with an application/environment)
  • Profiles
  • Reports
  • SAML Settings
  • Scans
  • Security Policies
  • Service Identities
  • Service Identity Tokens
  • System Announcement (aka banner)
  • Tags (aka User Tags)
  • Task Services
  • Tasks
  • Users

Proxies

Under the covers, python requests is being used to communicate with the Britive API. As such, any functionality of requests can be used, including setting an HTTP proxy.

  • HTTP proxies will be set via environment variables.
    • HTTP_PROXY
    • HTTPS_PROXY
    • NO_PROXY
    • http_proxy
    • https_proxy
    • no_proxy

Standard HTTP proxy URLs should be utilized.

Examples:

  • Unauthenticated Proxy: http://internalproxy.domain.com:8080
  • Authenticated Proxy: http://user:pass@internalproxy.domain.com:8080

Custom TLS Certificates

Setting custom TLS certificates functionality of requests can also be used.

  • Certificate bundles can be set via environment variables.
    • REQUESTS_CA_BUNDLE
    • CURL_CA_BUNDLE (used as a fallback)
    • PYBRITIVE_CA_BUNDLE (specific to the Britive Python SDK)

The values of these environment variables must be a path to a directory of certificates or a specific certificate.

Example: /path/to/certfile

Platform Examples

linux/macos

export REQUESTS_CA_BUNDLE="/usr/local/corp-proxy/cacert.pem"

windows

powershell:

$env:REQUESTS_CA_BUNDLE = "C:\Users\User\AppData\Local\corp-proxy\cacert.pem"

cmd:

set REQUESTS_CA_BUNDLE="C:\Users\User\AppData\Local\corp-proxy\cacert.pem"

Examples

Importing

This should be the only class that is required for import.

from britive.britive import Britive

Optionally, the various exceptions that this package raises can be imported as well, e.g.

from britive import exceptions

Then specific exception(s) could be referenced as demonstrated below:

try:
    something()
except exceptions.TokenMissingError():
    handle()

List All Users

from britive.britive import Britive
import json

britive = Britive()  # source needed data from environment variables

print(json.dumps(britive.identity_management.users.list(), indent=2, default=str))

Provide Needed Authentication Information in the Script

from britive.britive import Britive
import json

britive = Britive(tenant='example', token='...') # source token and tenant locally (not from environment variables)

print(json.dumps(britive.identity_management.users.list(), indent=2, default=str))

Create API Token for a Service Identity

from britive.britive import Britive
import json

britive = Britive()  # source needed data from environment variables

print(json.dumps(britive.identity_management.service_identity_tokens.create(service_identity_id='abc123'), indent=2, default=str))

Run a Report (JSON and CSV output)

from britive.britive import Britive
import json

britive = Britive()  # source needed data from environment variables

print(json.dumps(britive.reports.run(report_id='abc123'), indent=2, default=str))

with open('file.csv', 'w') as f:
    f.write(britive.reports.run(report_id='abc123', csv=True))

Create a Profile Policy (profiles v2/enhanced profiles)

The commands below will create a policy on a profile that allows user@domain.com to check out the profile but only if approver@domain.com approves that request within 10 minutes.

from britive.britive import Britive

b = Britive()

policy = b.application_management.profiles.policies.build(
    name='example',
    users=['user@domain.com'],
    approval_notification_medium='Email',
    approver_users=['approver@domain.com'],
    time_to_approve=10
)

b.application_management.profiles.policies.create(profile_id='...', policy=policy)

Release files for britive 4.6.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 britive 4.6.1
File Size Uploaded
britive-4.6.1.tar.gz 92.9 kB Details

Built distribution (wheel)

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

Total release size: 225.2 kB

Release files / britive-4.6.1.tar.gz

Download URL britive-4.6.1.tar.gz
Size 92.9 kB
Tags Source
SHA-256 checksum
How to use checksums
587891ae0f40bef4cb2a46dc6e3132623bbb1a69043e7ff05debf7e23cbb19b7
BLAKE2b-256 checksum
How to use checksums
07f784e6ab0f27be0af988922a8355875ff4ebbb2f1b3dabeac104d31fbd4b17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / britive-4.6.1-py3-none-any.whl

Download URL britive-4.6.1-py3-none-any.whl
Size 132.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2104b2f01b962403bf7fa0dda8c33cc4d08ef9de70573a6ecb90606c43309d0
BLAKE2b-256 checksum
How to use checksums
35dce6182bc8c470ef0e438f43d3da852da7ea47f6d432a7a99932a52d2a8555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

4.7.0

2 release files

This release

4.6.1 This release

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.2

2 release files

4.3.1

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.3

2 release files

4.1.2

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.22.0

2 release files

2.21.0

2 release files

2.20.1

2 release files

2.20.0

2 release files

2.18.0

2 release files

2.17.0

2 release files

2.15.1

2 release files

2.14.2

2 release files

2.14.1

2 release files

2.14.0

2 release files

2.12.3

2 release files

2.12.2

2 release files

2.12.1

2 release files

2.12.0

2 release files

2.11.1

2 release files

2.11.0

2 release files

2.9.0

2 release files

2.8.1

2 release files

2.8.0

2 release files

2.7.3

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