prom


Nameprom JSON
Version 5.0.0 PyPI version JSON
download
home_pageNone
SummaryA sensible orm for PostgreSQL or SQLite
upload_time2024-09-18 22:36:51
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseThe MIT License (MIT) Copyright (c) 2013+ Jay Marcyes Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords async postgresql postgres database db sqlite orm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Prom

An opinionated asynchronous lightweight orm for PostgreSQL or SQLite.


## 1 Minute Getting Started with SQLite

First, install prom:

    $ pip install prom[sqlite]

Set an environment variable:

    $ export PROM_DSN=sqlite://:memory:

Start python:

    $ python

Create a prom Orm:

```python
>>> import prom
>>>
>>> class Foo(prom.Orm):
...     table_name = "foo_table_name"
...     bar = prom.Field(int)
...
>>>
```

Now go wild and create some `Foo` objects:

```python
>>> for x in range(10):
...     f = await Foo.create(bar=x)
...
>>>
```

Now query them:

```python
>>> f = await Foo.query.one()
>>> f.bar
0
>>> f.pk
1
>>>
>>> async for f in await Foo.query.in_bar([3, 4, 5]):
...     f.pk
...
3
4
5
>>>
```

Update them:

```python
>>> async for f in await Foo.query:
...     f.bar += 100
...     await f.save()
...
>>>
```

and get rid of them:

```python
>>> async for f in await Foo.query:
...     await f.delete()
...
>>>
```

Congratulations, you have now created, retrieved, updated, and deleted from your database.


-------------------------------------------------------------------------------

## Configuration

Prom can be automatically configured on import by setting the environment variable `PROM_DSN`.

The `PROM_DSN` should 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 use `sqlite` and `postgres`.

So to use the builtin Postgres interface on `testdb` database on host `localhost` with username `testuser` and password `testpw`:

    postgres://testuser:testpw@localhost/testdb

And to set it in your environment:

    export PROM_DSN=postgres://testuser:testpw@localhost/testdb

After you've set the environment variable, then you just need to import Prom in your code:

```python
import prom
```

and Prom will take care of parsing the dsn url(s) and creating the connection(s) automatically.



### Multiple db interfaces or connections

If 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_2

It'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:

```python
import prom

class Orm1(prom.Orm):
    connection_name = "conn_1"
  
class Orm2(prom.Orm):
    connection_name = "conn_2"
```

Now, any child class that extends `Orm1` will use `conn_1` and any child class that extends `Orm2` will use `conn_2`.


## Creating Models

Checkout 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.


## Querying Rows

Checkout the [README](https://github.com/Jaymon/prom/blob/master/docs/README_QUERY.md) to see how to perform queries on the db.


## Versions

While Prom will most likely work on other versions, Prom is tested to work on 3.10.


## Installation


### Postgres

If you want to use Prom with Postgres:

    $ apt-get install libpq-dev python-dev
    $ pip install prom[postgres]


### Prom

Prom installs using pip:

    $ pip install prom[sqlite]
    $ pip install prom[postgres]

and to install the latest and greatest:

    $ pip install --upgrade "git+https://github.com/Jaymon/prom#egg=prom"


### Using for the first time

Prom 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.

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 crafting `ALTER` queries while developing.

If you want to install the tables manually, you can create a script or something and use the Orm's `install()` method:

```python
await SomeOrm.install()
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "prom",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "async, postgresql, postgres, database, db, sqlite, orm",
    "author": null,
    "author_email": "Jay Marcyes <jay@marcyes.com>",
    "download_url": "https://files.pythonhosted.org/packages/97/6c/8bfd1cc75503a8750f81a1190bba3dac186b50c49c9d73982a79c9f90f6e/prom-5.0.0.tar.gz",
    "platform": null,
    "description": "# 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>>> import prom\n>>>\n>>> class Foo(prom.Orm):\n...     table_name = \"foo_table_name\"\n...     bar = prom.Field(int)\n...\n>>>\n```\n\nNow go wild and create some `Foo` objects:\n\n```python\n>>> for x in range(10):\n...     f = await Foo.create(bar=x)\n...\n>>>\n```\n\nNow query them:\n\n```python\n>>> f = await Foo.query.one()\n>>> f.bar\n0\n>>> f.pk\n1\n>>>\n>>> async for f in await Foo.query.in_bar([3, 4, 5]):\n...     f.pk\n...\n3\n4\n5\n>>>\n```\n\nUpdate them:\n\n```python\n>>> async for f in await Foo.query:\n...     f.bar += 100\n...     await f.save()\n...\n>>>\n```\n\nand get rid of them:\n\n```python\n>>> async for f in await Foo.query:\n...     await f.delete()\n...\n>>>\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    <full.python.path.InterfaceClass>://<username>:<password>@<host>:<port>/<database>?<options=val&query=string>#<name>\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",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2013+ Jay Marcyes  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  ",
    "summary": "A sensible orm for PostgreSQL or SQLite",
    "version": "5.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Jaymon/prom",
        "Repository": "https://github.com/Jaymon/prom"
    },
    "split_keywords": [
        "async",
        " postgresql",
        " postgres",
        " database",
        " db",
        " sqlite",
        " orm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f3a46240d7010f65930bc70ff59ba76bb14728ebc015c61d7c825d38768951e",
                "md5": "6a1e82e6c9a633b090f7710cdaa6dec4",
                "sha256": "f43aa3e118ca013ff59434546bd11ac4264539fcb9ee2859df30df70d72c98d6"
            },
            "downloads": -1,
            "filename": "prom-5.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a1e82e6c9a633b090f7710cdaa6dec4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 80208,
            "upload_time": "2024-09-18T22:36:52",
            "upload_time_iso_8601": "2024-09-18T22:36:52.994258Z",
            "url": "https://files.pythonhosted.org/packages/7f/3a/46240d7010f65930bc70ff59ba76bb14728ebc015c61d7c825d38768951e/prom-5.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "976c8bfd1cc75503a8750f81a1190bba3dac186b50c49c9d73982a79c9f90f6e",
                "md5": "62dca5b120d68d4dae7254d0d5e1b732",
                "sha256": "673c309bab0a8783a02d81b9a682949d78c492115918bb9047b4122a162419da"
            },
            "downloads": -1,
            "filename": "prom-5.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "62dca5b120d68d4dae7254d0d5e1b732",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 80506,
            "upload_time": "2024-09-18T22:36:51",
            "upload_time_iso_8601": "2024-09-18T22:36:51.354764Z",
            "url": "https://files.pythonhosted.org/packages/97/6c/8bfd1cc75503a8750f81a1190bba3dac186b50c49c9d73982a79c9f90f6e/prom-5.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-18 22:36:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Jaymon",
    "github_project": "prom",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "prom"
}
        
Elapsed time: 0.33212s