{"id":16444941,"url":"https://github.com/jaymon/prom","last_synced_at":"2025-03-16T17:36:46.516Z","repository":{"id":9557976,"uuid":"11467297","full_name":"Jaymon/prom","owner":"Jaymon","description":"A PostgreSQL or SQLite orm for Python","archived":false,"fork":false,"pushed_at":"2024-04-15T06:26:48.000Z","size":1384,"stargazers_count":21,"open_issues_count":28,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-04-16T19:00:22.244Z","etag":null,"topics":["async","async-await","asynchronous","asyncio","dsn","orm","postgres","postgresql-database","python","python3","sqlite","sqlite-database","sqlite-orm"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jaymon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2013-07-17T04:40:05.000Z","updated_at":"2024-04-21T18:58:15.761Z","dependencies_parsed_at":"2023-11-17T00:48:25.969Z","dependency_job_id":"d286fb3c-01c3-45b0-82a0-7062a91dce43","html_url":"https://github.com/Jaymon/prom","commit_stats":{"total_commits":299,"total_committers":2,"mean_commits":149.5,"dds":"0.010033444816053505","last_synced_commit":"d45ed58c0964b00749a92d5d2489c74f7fa63767"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaymon%2Fprom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaymon%2Fprom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaymon%2Fprom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jaymon%2Fprom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jaymon","download_url":"https://codeload.github.com/Jaymon/prom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243823783,"owners_count":20353730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","async-await","asynchronous","asyncio","dsn","orm","postgres","postgresql-database","python","python3","sqlite","sqlite-database","sqlite-orm"],"created_at":"2024-10-11T09:42:41.962Z","updated_at":"2025-03-16T17:36:46.165Z","avatar_url":"https://github.com/Jaymon.png","language":"Python","readme":"# Prom\n\nAn opinionated asynchronous lightweight orm for PostgreSQL or SQLite.\n\n\n## 1 Minute Getting Started with SQLite\n\nFirst, install prom:\n\n    $ pip install prom[sqlite]\n\nSet an environment variable:\n\n    $ export PROM_DSN=sqlite://:memory:\n\nStart python:\n\n    $ python\n\nCreate a prom Orm:\n\n```python\n\u003e\u003e\u003e import prom\n\u003e\u003e\u003e\n\u003e\u003e\u003e class Foo(prom.Orm):\n...     table_name = \"foo_table_name\"\n...     bar = prom.Field(int)\n...\n\u003e\u003e\u003e\n```\n\nNow go wild and create some `Foo` objects:\n\n```python\n\u003e\u003e\u003e for x in range(10):\n...     f = await Foo.create(bar=x)\n...\n\u003e\u003e\u003e\n```\n\nNow query them:\n\n```python\n\u003e\u003e\u003e f = await Foo.query.one()\n\u003e\u003e\u003e f.bar\n0\n\u003e\u003e\u003e f.pk\n1\n\u003e\u003e\u003e\n\u003e\u003e\u003e async for f in await Foo.query.in_bar([3, 4, 5]):\n...     f.pk\n...\n3\n4\n5\n\u003e\u003e\u003e\n```\n\nUpdate them:\n\n```python\n\u003e\u003e\u003e async for f in await Foo.query:\n...     f.bar += 100\n...     await f.save()\n...\n\u003e\u003e\u003e\n```\n\nand get rid of them:\n\n```python\n\u003e\u003e\u003e async for f in await Foo.query:\n...     await f.delete()\n...\n\u003e\u003e\u003e\n```\n\nCongratulations, you have now created, retrieved, updated, and deleted from your database.\n\n\n-------------------------------------------------------------------------------\n\n## Configuration\n\nProm can be automatically configured on import by setting the environment variable `PROM_DSN`.\n\nThe `PROM_DSN` should define a dsn url:\n\n    \u003cfull.python.path.InterfaceClass\u003e://\u003cusername\u003e:\u003cpassword\u003e@\u003chost\u003e:\u003cport\u003e/\u003cdatabase\u003e?\u003coptions=val\u0026query=string\u003e#\u003cname\u003e\n\nThe built-in interface classes don't need their full python paths, you can just use `sqlite` and `postgres`.\n\nSo to use the builtin Postgres interface on `testdb` database on host `localhost` with username `testuser` and password `testpw`:\n\n    postgres://testuser:testpw@localhost/testdb\n\nAnd to set it in your environment:\n\n    export PROM_DSN=postgres://testuser:testpw@localhost/testdb\n\nAfter you've set the environment variable, then you just need to import Prom in your code:\n\n```python\nimport prom\n```\n\nand Prom will take care of parsing the dsn url(s) and creating the connection(s) automatically.\n\n\n\n### Multiple db interfaces or connections\n\nIf you have multiple connections, you can actually set multiple environment variables:\n\n    export PROM_DSN_1=postgres://testuser:testpw@localhost/testdb1#conn_1\n    export PROM_DSN_2=sqlite://testuser:testpw@localhost/testdb2#conn_2\n\nIt's easy to have one set of `prom.Orm` children use one connection and another set use a different connection, since the fragment part of a Prom dsn url sets the name:\n\n```python\nimport prom\n\nclass Orm1(prom.Orm):\n    connection_name = \"conn_1\"\n  \nclass Orm2(prom.Orm):\n    connection_name = \"conn_2\"\n```\n\nNow, any child class that extends `Orm1` will use `conn_1` and any child class that extends `Orm2` will use `conn_2`.\n\n\n## Creating Models\n\nCheckout the [README](https://github.com/Jaymon/prom/blob/master/docs/README_MODEL.md) to see how to define the db schema and create models your python code can use.\n\n\n## Querying Rows\n\nCheckout the [README](https://github.com/Jaymon/prom/blob/master/docs/README_QUERY.md) to see how to perform queries on the db.\n\n\n## Versions\n\nWhile Prom will most likely work on other versions, Prom is tested to work on 3.10.\n\n\n## Installation\n\n\n### Postgres\n\nIf you want to use Prom with Postgres:\n\n    $ apt-get install libpq-dev python-dev\n    $ pip install prom[postgres]\n\n\n### Prom\n\nProm installs using pip:\n\n    $ pip install prom[sqlite]\n    $ pip install prom[postgres]\n\nand to install the latest and greatest:\n\n    $ pip install --upgrade \"git+https://github.com/Jaymon/prom#egg=prom\"\n\n\n### Using for the first time\n\nProm 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 your `prom.model.Orm` child 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.\n\nLikewise, 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 crafting `ALTER` queries while developing.\n\nIf you want to install the tables manually, you can create a script or something and use the Orm's `install()` method:\n\n```python\nawait SomeOrm.install()\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaymon%2Fprom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaymon%2Fprom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaymon%2Fprom/lists"}