Package: prom
PromAn opinionated lightweight orm for PostgreSQL or SQLite.Prom has been used in both single threaded and multi-threaded environments, including environments using Greenthreads.1 Minute Getting Started with SQLiteFirst, install prom:$ pip install promSet an environment variable:$ export PROM_DSN=sqlite://:memory:Start python:$ pythonCreate a prom Orm:>>>importprom>>>>>>classFoo(prom.Orm):...table_name="foo_table_name"...bar=prom.Field(int)...>>>Now go wild and create someFooobjects:>>>forxinrange(10):...f=Foo.create(bar=x)...>>>Now query them:>>>f=Foo.query.one()>>>f.bar0>>>f.pk1>>>>>>forfinFoo.query.in_bar([3,4,5]):...f.pk...345>>>Update them:>>>forfinFoo.query:...f.bar+=100...f.save()...>>>and get rid of them:>>>forfinFoo.query:...f.delete()...>>>Congratulations, you have now created, retrieved, updated, and deleted from your database.ConfigurationProm can be automatically configured on import by setting the environment variablePROM_DSN.ThePROM_DSNshould define a dsn url:<full.python.path.InterfaceClass>://<username>:<password>@<host>:<port>/<database>?<options=val&query=string>#<name>The built-in interface classes don't need their full python paths, you can just usesqliteandpostgres.So to use the builtin Postgres interface ontestdbdatabase on hostlocalhostwith usernametestuserand passwordtestpw:postgres://testuser:testpw@localhost/testdbAnd to set it in your environment:export PROM_DSN=postgres://testuser:testpw@localhost/testdbAfter you've set the environment variable, then you just need to import Prom in your code:importpromand Prom will take care of parsing the dsn url(s) and creating the connection(s) automatically.Multiple db interfaces or connectionsIf you have multiple connections, you can actually set multiple environment variables:export PROM_DSN_1=postgres://testuser:testpw@localhost/testdb1#conn_1
export PROM_DSN_2=sqlite://testuser:testpw@localhost/testdb2#conn_2It's easy to have one set ofprom.Ormchildren use one connection and another set use a different connection, since the fragment part of a Prom dsn url sets the name:importpromprom.configure("Interface://testuser:testpw@localhost/testdb#connection_1")prom.configure("Interface://testuser:testpw@localhost/testdb#connection_2")classOrm1(prom.Orm):connection_name="connection_1"classOrm2(prom.Orm):connection_name="connection_2"Now, any child class that extendsOrm1will useconnection_1and any child class that extendsOrm2will useconnection_2.Creating ModelsCheckout theREADMEto see how to define the db schema and create models your python code can use.Querying RowsCheckout theREADMEto see how to perform queries on the db.VersionsWhile Prom will most likely work on other versions, Prom is tested to work on 2.7+ and 3.8.InstallationPostgresIf you want to use Prom with Postgres, you need psycopg2:$ apt-get install libpq-dev python-dev
$ pip install psycopgGreen ThreadsIf you want to use Prom with gevent, you'll need gevent and psycogreen:$ pip install gevent
$ pip install psycogreenThese are the versions we're using:$ pip install "gevent==20.6.2"
$ pip install "psycogreen==1.0"Then you can setup Prom like this:fromprom.interface.postgresimportgeventgevent.patch_all()Now you can use Prom in the same way you always have. If you would like to configure the threads and stuff, you can pass in some configuration options using the dsn, the three parameters areasync,pool_maxconn,pool_minconn, andpool_class. The only one you'll really care about ispool_maxconnwhich sets how many connections should be created.PromProm installs using pip:$ pip install promand to install the latest and greatest:$ pip install --upgrade "git+https://github.com/Jaymon/prom#egg=prom"Using for the first timeProm takes the approach that you don't want to be hassled with table installation while developing, so when it tries to do something and sees that the table doesn't yet exist, it will use your defined fields for yourprom.model.Ormchild and create a table for you, that way you don't have to remember to run a script or craft some custom db query to add your tables. Prom takes care of that for you automatically.Likewise, if you add a field (and the field is not required) then prom will go ahead and add that field to your table so you don't have to bother with craftingALTERqueries while developing.If you want to install the tables manually, you can create a script or something and use the Orm'sinstall()method:SomeOrm.install()