Hide code cell content

# Hidden using cell tags!
# Normally, you dont need to set this variable if you are using
# the default deployment of the backend
import os

os.environ["SNIP_DEPLOYMENT_URL"] = "https://snip:4000"
os.environ["SNIP_ADDITIONAL_REQUEST_ARGS"] = '{"verify": false}'

# Hide InsecureRequestWarning
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Account Endpoints

The python package provides a simple wrapper around the account api. All API methods need either an account token or a book specific token. To find which method needs which token please check the call signature of all functions below.

from snip.token import get_all_tokens, AccountToken

# Get account token
tokens = get_all_tokens()
account_tokens= list(filter(
    lambda t: isinstance(t, AccountToken), tokens[0]
))
if len(account_tokens) == 0:
    raise ValueError("No account token found. Please create one first.")
account_token: AccountToken = account_tokens[0]

Retrieve all groups

Get a list of all groups the user is a member of, the user is inferred from the token.

from snip.api.account import get_groups

all_groups = get_groups(token=account_token)
all_groups
[{'id': 2,
  'name': 'whatagroup',
  'description': 'fooasdasdassda',
  'created': datetime.datetime(2025, 9, 29, 9, 49, 17, tzinfo=datetime.timezone.utc),
  'last_updated': datetime.datetime(2025, 9, 29, 9, 49, 17, tzinfo=datetime.timezone.utc),
  'members': [{'user_id': 1,
    'group_id': 2,
    'role': 'owner',
    'joined_at': datetime.datetime(2025, 9, 29, 9, 49, 17, tzinfo=datetime.timezone.utc),
    'primary_credential_id': 1,
    'emails': ['sebastian@mohrenclan.de'],
    'emails_verified': [True],
    'credential_ids': [1],
    'credential_types': ['password'],
    'group_name': 'whatagroup',
    'group_description': 'fooasdasdassda',
    'self': True}]},
 {'id': 3,
  'name': 'Test Group',
  'description': None,
  'created': datetime.datetime(2025, 10, 14, 12, 46, 51, tzinfo=datetime.timezone.utc),
  'last_updated': datetime.datetime(2025, 10, 14, 12, 46, 51, tzinfo=datetime.timezone.utc),
  'members': [{'user_id': 1,
    'group_id': 3,
    'role': 'owner',
    'joined_at': datetime.datetime(2025, 10, 14, 12, 46, 51, tzinfo=datetime.timezone.utc),
    'primary_credential_id': 1,
    'emails': ['sebastian@mohrenclan.de'],
    'emails_verified': [True],
    'credential_ids': [1],
    'credential_types': ['password'],
    'group_name': 'Test Group',
    'group_description': None,
    'self': True}]},
 {'id': 4,
  'name': 'Test Group',
  'description': None,
  'created': datetime.datetime(2025, 10, 14, 12, 56, 19, tzinfo=datetime.timezone.utc),
  'last_updated': datetime.datetime(2025, 10, 14, 12, 56, 19, tzinfo=datetime.timezone.utc),
  'members': [{'user_id': 1,
    'group_id': 4,
    'role': 'owner',
    'joined_at': datetime.datetime(2025, 10, 14, 12, 56, 19, tzinfo=datetime.timezone.utc),
    'primary_credential_id': 1,
    'emails': ['sebastian@mohrenclan.de'],
    'emails_verified': [True],
    'credential_ids': [1],
    'credential_types': ['password'],
    'group_name': 'Test Group',
    'group_description': None,
    'self': True}]},
 {'id': 5,
  'name': 'Test Group',
  'description': None,
  'created': datetime.datetime(2025, 10, 14, 12, 57, 9, tzinfo=datetime.timezone.utc),
  'last_updated': datetime.datetime(2025, 10, 14, 12, 57, 9, tzinfo=datetime.timezone.utc),
  'members': [{'user_id': 1,
    'group_id': 5,
    'role': 'owner',
    'joined_at': datetime.datetime(2025, 10, 14, 12, 57, 9, tzinfo=datetime.timezone.utc),
    'primary_credential_id': 1,
    'emails': ['sebastian@mohrenclan.de'],
    'emails_verified': [True],
    'credential_ids': [1],
    'credential_types': ['password'],
    'group_name': 'Test Group',
    'group_description': None,
    'self': True}]},
 {'id': 7,
  'name': 'Test Group',
  'description': None,
  'created': datetime.datetime(2025, 10, 14, 12, 59, 30, tzinfo=datetime.timezone.utc),
  'last_updated': datetime.datetime(2025, 10, 14, 12, 59, 30, tzinfo=datetime.timezone.utc),
  'members': [{'user_id': 1,
    'group_id': 7,
    'role': 'owner',
    'joined_at': datetime.datetime(2025, 10, 14, 12, 59, 30, tzinfo=datetime.timezone.utc),
    'primary_credential_id': 1,
    'emails': ['sebastian@mohrenclan.de'],
    'emails_verified': [True],
    'credential_ids': [1],
    'credential_types': ['password'],
    'group_name': 'Test Group',
    'group_description': None,
    'self': True}]}]

Get, Create, Update, Delete a specific group

It is possible to get, create, update and delete a specific group. The user is inferred from the token but you have to provide the group id.

from snip.api.account import get_group, create_group, modify_group, delete_group

# Create group
new_group = create_group(name="Test Group", token=account_token)
new_group
{'id': 9,
 'name': 'Test Group',
 'description': None,
 'created': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
 'last_updated': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
 'members': [{'user_id': 1,
   'group_id': 9,
   'role': 'owner',
   'joined_at': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
   'primary_credential_id': 1,
   'emails': ['sebastian@mohrenclan.de'],
   'emails_verified': [True],
   'credential_ids': [1],
   'credential_types': ['password'],
   'group_name': 'Test Group',
   'group_description': None,
   'self': True}]}
# Get group by id
new_group = get_group(group_id=new_group["id"], token=account_token)
new_group
{'id': 9,
 'name': 'Test Group',
 'description': None,
 'created': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
 'last_updated': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
 'members': [{'user_id': 1,
   'group_id': 9,
   'role': 'owner',
   'joined_at': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
   'primary_credential_id': 1,
   'emails': ['sebastian@mohrenclan.de'],
   'emails_verified': [True],
   'credential_ids': [1],
   'credential_types': ['password'],
   'group_name': 'Test Group',
   'group_description': None,
   'self': True}]}
# Modify group
new_group = modify_group(
    group_id=new_group["id"], name="Modified Test Group", token=account_token
)
new_group
{'id': 9,
 'name': 'Modified Test Group',
 'description': None,
 'created': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
 'last_updated': datetime.datetime(2025, 10, 14, 13, 13, 3, tzinfo=datetime.timezone.utc),
 'members': [{'user_id': 1,
   'group_id': 9,
   'role': 'owner',
   'joined_at': datetime.datetime(2025, 10, 14, 13, 8, 20, tzinfo=datetime.timezone.utc),
   'primary_credential_id': 1,
   'emails': ['sebastian@mohrenclan.de'],
   'emails_verified': [True],
   'credential_ids': [1],
   'credential_types': ['password'],
   'group_name': 'Modified Test Group',
   'group_description': None,
   'self': True}]}
# Delete group
delete_group(group_id=new_group["id"], token=account_token)

# Further calls to get this group will error now
# get_group(group_id=new_group["id"], token=account_token) -> Exception