import pickle

database = {}
# ... Fill the database

# Open the `database.bin` file in write mode
my_file = open('database.bin', 'w')
pickle.dump(database, my_file)
my_file.close()
# The `database` object is saved in the
# `database.bin` file!

# Open the `database.bin` file in read mode
my_file = open('database.bin', 'w')
my_file = open('database.bin', 'r')
restored_database = pickle.load(my_file)
my_file.close()
# `database` and `restored_database` have the
# same content!