Skip to main content

Provides functions to work with TeamPasswordManager API.

Project description

tpm.py

Modern Python SDK groundwork for TeamPasswordManager with safer API boundaries and maintainable packaging.

CI Quality Gate Status PyPI version Python version License

Support via bunq

A Python Module for the TeamPasswordManager API

Requires: requests

Install tpm.py

You can install the tpm module via pip

pip install tpm

How to Use

This is an example how you can use it in a python script

#! /usr/bin/env python
import tpm
# create a object for the connection settings
URL = "https://mypasswordmanager.example.com"
USER = 'example-user'
PASS = 'EXAMPLE_PASSWORD'
tpmconn = tpm.TpmApiv5(URL, username=USER, password=PASS)

# get a dictionary for all password entries
data = tpmconn.list_passwords()
# show all names from the password entries
for item in data:
    print (item.get('name'))

You can also use Private/Public Key authentication

#! /usr/bin/env python
import tpm
# create a object for the connection settings
URL = "https://mypasswordmanager.example.com"
pubkey = 'EXAMPLE_PUBLIC_KEY'
privkey = 'EXAMPLE_PRIVATE_KEY'
tpmconn = tpm.TpmApiv5(URL, private_key=privkey, public_key=pubkey)

# get a dictionary for all password entries
data = tpmconn.list_passwords()
# show all names from the password entries
for item in data:
    print (item.get('name'))

If you always want to unlock entries that are locked, you can specify an unlock reason

tpmconn = tpm.TpmApiv5(URL, username=USER, password=PASS, unlock_reason="Because I can!")

TLS certificate verification

TLS certificates are verified by default (verify=True). To connect to a server with a self-signed certificate you can disable verification or point to a custom CA bundle:

# disable verification (not recommended)
tpmconn = tpm.TpmApiv5(URL, username=USER, password=PASS, verify=False)

# or verify against a custom CA bundle
tpmconn = tpm.TpmApiv5(URL, username=USER, password=PASS, verify="/path/to/ca-bundle.pem")

API v6

Use tpm.TpmApiv6 to talk to the v6 API. It inherits every function from the previous versions and adds the endpoints introduced in v6 (see the Functions explained section, marked (since v6)):

tpmconn = tpm.TpmApiv6(URL, username=USER, password=PASS)

Page size

Since v6 you can set the page size for paginated requests via the X-Page-Size header. Pass page_size (an integer between 5 and 1000) when creating the client:

tpmconn = tpm.TpmApiv6(URL, username=USER, password=PASS, page_size=100)

Development artifact guard

This repository uses pre-commit to keep public artifacts safe to publish. Install the hook once after cloning:

python3 -m pip install pre-commit
pre-commit install --install-hooks

Before opening a PR, run:

pre-commit run --all-files

The guard blocks accidental literal backslash-n text where real line breaks belong, local machine paths, internal workflow details, and obvious secret or auth-token values. Replace real values with placeholders or environment-variable references before publishing.

Logging

Every function call leads to a at least a logging message. If you want to log all your script does, you can do it like this:

import logging

# set log file and log level
logfile = 'MyLogFile.log'
loglevel = logging.INFO
logformat = '%(asctime)s - %(levelname)s - %(message)s'

logging.basicConfig(filename=logfile, level=loglevel, format=logformat)
# If you don't want the requests and urllib3 module to log too much
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)

Functions explained

All Functions are also explained at the API documentation


API Projects

List Projects

list_projects()

list_projects_archived()

list_projects_favorite()

list_projects_search(searchstring)

(since v4) List Subprojects

list_subprojects(ID)

list_subprojects_action(ID, action)

Show Project

show_project(ID)

List Passwords of Project

list_passwords_of_project(ID)

List User Access on Project

list_user_access_on_project(ID)

Create Project

create_project(data)

Update Project

update_project(ID, data)

Change Parent of Project

change_parent_of_project(ID, NewParentID)

Update Security of Project

update_security_of_project(ID, data)

Archive Project

archive_project(ID)

Unarchive Project

unarchive_project(ID)

Delete Project

delete_project(ID)

API Passwords

List Passwords

list_passwords()

list_passwords_archived()

list_passwords_favorite()

list_passwords_search(searchstring)

Show Password

show_password(ID)

List User Access on Password

list_user_access_on_password(ID)

Create Password

create_password(data)

Update Password

update_password(ID, data)

Update Security of Password

update_security_of_password(ID, data)

Update Custom Fields of Password

update_custom_fields_of_password(ID, data)

Delete Password

delete_password(ID)

Lock Password

lock_password(ID)

Unlock Password

unlock_password(ID)

(since v5) Archive Password

archive_password(ID)

(since v5) Unarchive Password

unarchive_password(ID)

(since v5) Move Password

move_password(ID, PROJECT_ID)

API MyPasswords

(since v6) List Archived MyPasswords

list_mypasswords_archived()

(since v6) List Favorite MyPasswords

list_mypasswords_favorite()

List MyPasswords

list_mypasswords()

list_mypasswords_search(searchstring)

Show MyPassword

show_mypassword(ID)

Create MyPassword

create_mypassword(data)

Update MyPassword

update_mypassword(ID, data)

Delete MyPassword

delete_mypassword(ID)

API Favorites

Set Favorite Password

set_favorite_password(ID)

Unset Favorite Password

unset_favorite_password(ID)

Set Favorite Project

set_favorite_project(ID)

Unset Favorite Project

unset_favorite_project(ID)

Note: TpmApiv6 overrides these two to use the v6 endpoint favorite_projects/{ID}.json (plural); earlier versions use favorite_project/{ID}.json.

(since v6) Set Favorite MyPassword

set_favorite_mypassword(ID)

(since v6) Unset Favorite MyPassword

unset_favorite_mypassword(ID)

Move MyPassword to a Project

move_mypassword(ID, PROJECT_ID)

API Users

List Users

list_users()

Show User

show_user(ID)

(since v6) List Passwords a User can access

list_user_passwords(ID)

(since v6) List Projects a User can access

list_user_projects(ID)

Show Me/Who am I?

show_me() who_am_i()

Create User

create_user(data)

(since v5) Create LDAP User

create_user_ldap(data)

(since v5) Create SAML User

create_user_saml(data)

Update User

update_user(ID, data)

Change User Password

change_user_password(ID, data)

Activate User

activate_user(ID)

Deactivate User

deactivate_user(ID)

Convert User to LDAP

convert_user_to_ldap(ID, DN) convert_ldap_user_to_normal(ID)

(since v5) Convert User to LDAP

convert_user_to_ldap(ID, DN, SERVER_ID)

(since v5) Convert User to SAML

convert_user_to_saml(ID)

Delete User

delete_user(ID)

API Groups

List groups

list_groups()

Show Group

show_group(ID)

Create Group

create_group(data)

Update Group

update_group(ID, data):

Add User to Group

add_user_to_group(GroupID, UserID)

Delete User from Group

delete_user_from_group(GroupID, UserID)

Delete Group

delete_group(ID)

Files

(since v5) List Files of Project

list_project_files(ID)

(since v5) List Files of Password

list_password_files(ID)

(since v5) Upload a file to a project

upload_project_file(ID, file, notes="optional notes")

(since v5) Upload a file to a password

upload_password_file(ID, file, notes="optional notes")

(since v5) Show info of a file

show_file_info(ID)

(since v5) Updates notes of a file

update_file_notes(ID, NOTES)

(since v5) Show max upload file size

max_upload_file_size()

(since v5) Download a file

download_file(ID)

(since v5) Delete a file

delete_file(ID)

API Password Generator

generate_password()

API Version

get_version() get_latest_version() up_to_date()

(since v6) API Log

(since v6) List Log

list_log()

(since v6) Search Log

list_log_search(searchstring)

Governance

Support

If this Python SDK is useful to you, you can support its ongoing maintenance via bunq. Support is voluntary and appreciated, but does not create any entitlement to support, features, consulting, an SLA, or invoice-based work.

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

tpm-5.0.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tpm-5.0.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file tpm-5.0.0.tar.gz.

File metadata

  • Download URL: tpm-5.0.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tpm-5.0.0.tar.gz
Algorithm Hash digest
SHA256 9ff265ae69fa95d5787c33d246926661139b79f104bbb9bf141b6af46f7d477f
MD5 fe79864e329d8eda6e6913dd0565b46e
BLAKE2b-256 de04e8871a26fc2683497d82a32a4c137d7139133fbcabe678f4eb258bdd9d96

See more details on using hashes here.

Provenance

The following attestation bundles were made for tpm-5.0.0.tar.gz:

Publisher: release.yml on peshay/tpm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tpm-5.0.0-py3-none-any.whl.

File metadata

  • Download URL: tpm-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tpm-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34209373c569167f9555d6ef967ac16666867080493d826d6a4b5ca6f40aa8da
MD5 8e3ae2b7473b7141704b59af9b45f0a9
BLAKE2b-256 61823003a58ae889eb086c8c320fd5c73b69a9a6a7a2bedc7eb1e5dcf1c6fa54

See more details on using hashes here.

Provenance

The following attestation bundles were made for tpm-5.0.0-py3-none-any.whl:

Publisher: release.yml on peshay/tpm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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