tpm.py
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://mypasswordpanager.example.com"
USER = 'MyUser'
PASS = 'Secret'
tpmconn = tpm.TpmApiv4(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 = '3726d93f2a0e5f0fe2cc3a6e9e3ade964b43b07f897d579466c28b7f8ff51cd0'
privkey = '87324bedead51af96a45271d217b8ad5ef3f220da6c078a9bce4e4318729189c'
tpmconn = tpm.TpmApiv4(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.TpmApiv4(URL, username=USER, password=PASS, unlock_reason="Because I can!")
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)
List Subprojects
(v4 Only)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 Parten of Project
change_parent_of_project(ID, NewParrentID)
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)
API MyPasswords
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)
API Users
List Users
list_users()
Show User
show_user(ID)
Show Me/Who am I?
show_me() who_am_i()
Create User
create_user(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)
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)
API Password Generator
generate_password()
API Version
get_version() get_latest_version() up_to_date()