Creating an entity instance

Creating an entity instance in Pony is similar to creating a regular object in Python:

  1. customer1 = Customer(login="John", password="***",
  2. name="John", email="john@google.com")

When creating an object in Pony, all the parameters should be specified as keyword arguments. If an attribute has a default value, you can omit it.

All created instances belong to the current db_session(). In some object-relational mappers, you are required to call an object’s save() method in order to save it. This is inconvenient, as a programmer must track which objects were created or updated, and must not forget to call the save() method on each object.

Pony tracks which objects were created or updated and saves them in the database automatically when current db_session() is over. If you need to save newly created objects before leaving the db_session() scope, you can do so by using the flush() or commit() functions.