Moving from pwsafe to KeePass

My favourite password management tool, pwsafe, is getting old. It’s no longer part of Ubuntu and I’ve had to compile it myself for quite a while now. It’s also not supported on Android, and shows other signs of aging. So, I moved to KeePass. Exporting my database to CSV was simple, and to make the job of importing it correctly into KeePass even easier, I wrote a simple Python script.

import csv

infile = open('passwords.csv', encoding='utf-8')
outfile = open('passwords-groupfixed.csv', 'w', encoding='utf-8', newline='')
incsv = csv.reader(infile, delimiter='\t')
outcsv = csv.writer(outfile)

for rowidx, row in enumerate(incsv):
    if rowidx == 0:
        # Skip comment row

    if rowidx == 1:
        outcsv.writerow(['uuid', 'Title', 'User name', 'Password', 'Notes', 'URL'])

    if len(row) != 6:
        raise SystemExit('Weird row: {}'.format(row))

    uuid, group, name, login, passwd, notes = row
    if group:
        name = group + '.' + name

    url = ''
    if notes.startswith('http') or notes.startswith('www'):
        url, notes = notes, url

    outcsv.writerow([uuid, name, login, passwd, notes, url])

This script takes the pwsafe CSV and transforms it into a CSV file that can be plugged into KeePass without any further configuration. Nice and easy!

dr. Sybren A. Stüvel
dr. Sybren A. Stüvel
Open Source software developer, photographer, drummer, and electronics tinkerer