>>> import parse >>> format_string = 'PN-{:0>9}' >>> id = 123 >>> pn = format_string.format(id) >>> pn 'PN-000000123' >>> parsed = parse.parse(format_string, pn) >>> parsed <Result ('123',) {}> >>> parsed[0] '123'