pgfusion


Namepgfusion JSON
Version 0.0.11 PyPI version JSON
download
home_pageNone
SummaryAn asyncpg wrapper with a simple api
upload_time2022-12-12 07:56:55
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10.4
licenseMIT
keywords asyncio asyncpg postgres python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pgfusion

[![PyPI version](https://badge.fury.io/py/pgfusion.svg)](https://pypi.org/project/pgfusion/)

An asyncpg wrapper with a simple api.

The only dependency for **pgfusion** is
[asyncpg](https://github.com/MagicStack/asyncpg), and the api wrapper is very similar to
the api provieded by the [databases](https://github.com/encode/databases) package.

## Installation

```bash
$ pip install pgfusion
```

## Quickstart

```python
from pgfusion import Database

database = Database("postgresql://username:password@localhost:5432/postgres")
await database.connect()

# Execute a query
query = """
  create table high_scores (
    id uuid primary key default gen_random_uuid(),
    name varchar(100) not null,
    score integer not null
  )
"""
await database.execute(query)

# Execute many queries
query = "insert into high_scores (name, score) values (:name, :score)"
values = [
  {"name": "George", "score": 43},
  {"name": "Jess", "score": 67},
  {"name": "Kevin", "score": 30}
]
await database.execute_many(query, values)

# Fetch many rows
query = "select * from high_scores"
records = await database.fetch_many(query)
assert(len(records) == 3)

# Fetch a row
query = "select * from high_scores where name = :name"
values = {"name": "George"}
record = await database.fetch_one(query, values)
assert(record.score == 43)

# Fetch a value
query = "select name from high_scores where score = :score"
values = {"score": 30}
value = await database.fetch_val(query, values)
assert(value == "Kevin")

# Copy records to a table (via Postgres COPY)
await database.copy_records_to_table(
  "high_scores",
  records=[("Mav", 200), ("Connor", 134)],
  columns=["name", "score"]
)

# Work with individual connections
async with database.connection() as connection:
  ...

  # Create a transaction
  async with connection.transaction():
    ...

await database.disconnect()
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pgfusion",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10.4",
    "maintainer_email": null,
    "keywords": "asyncio,asyncpg,postgres,python",
    "author": null,
    "author_email": "Wayde Gilliam <waydegilliam@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/fd/0e/8dba71f7df2ac127ec6acfb1a551cb7680c5276b669bb0a2c18cd70bd4c4/pgfusion-0.0.11.tar.gz",
    "platform": null,
    "description": "# pgfusion\n\n[![PyPI version](https://badge.fury.io/py/pgfusion.svg)](https://pypi.org/project/pgfusion/)\n\nAn asyncpg wrapper with a simple api.\n\nThe only dependency for **pgfusion** is\n[asyncpg](https://github.com/MagicStack/asyncpg), and the api wrapper is very similar to\nthe api provieded by the [databases](https://github.com/encode/databases) package.\n\n## Installation\n\n```bash\n$ pip install pgfusion\n```\n\n## Quickstart\n\n```python\nfrom pgfusion import Database\n\ndatabase = Database(\"postgresql://username:password@localhost:5432/postgres\")\nawait database.connect()\n\n# Execute a query\nquery = \"\"\"\n  create table high_scores (\n    id uuid primary key default gen_random_uuid(),\n    name varchar(100) not null,\n    score integer not null\n  )\n\"\"\"\nawait database.execute(query)\n\n# Execute many queries\nquery = \"insert into high_scores (name, score) values (:name, :score)\"\nvalues = [\n  {\"name\": \"George\", \"score\": 43},\n  {\"name\": \"Jess\", \"score\": 67},\n  {\"name\": \"Kevin\", \"score\": 30}\n]\nawait database.execute_many(query, values)\n\n# Fetch many rows\nquery = \"select * from high_scores\"\nrecords = await database.fetch_many(query)\nassert(len(records) == 3)\n\n# Fetch a row\nquery = \"select * from high_scores where name = :name\"\nvalues = {\"name\": \"George\"}\nrecord = await database.fetch_one(query, values)\nassert(record.score == 43)\n\n# Fetch a value\nquery = \"select name from high_scores where score = :score\"\nvalues = {\"score\": 30}\nvalue = await database.fetch_val(query, values)\nassert(value == \"Kevin\")\n\n# Copy records to a table (via Postgres COPY)\nawait database.copy_records_to_table(\n  \"high_scores\",\n  records=[(\"Mav\", 200), (\"Connor\", 134)],\n  columns=[\"name\", \"score\"]\n)\n\n# Work with individual connections\nasync with database.connection() as connection:\n  ...\n\n  # Create a transaction\n  async with connection.transaction():\n    ...\n\nawait database.disconnect()\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An asyncpg wrapper with a simple api",
    "version": "0.0.11",
    "split_keywords": [
        "asyncio",
        "asyncpg",
        "postgres",
        "python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "md5": "87d6af83dfa8fcb34d97334a8dbefb1c",
                "sha256": "9357e4edc716004ebd6333b64a431d85904a947c1b068219c050369e3c7d10a1"
            },
            "downloads": -1,
            "filename": "pgfusion-0.0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87d6af83dfa8fcb34d97334a8dbefb1c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10.4",
            "size": 5112,
            "upload_time": "2022-12-12T07:56:59",
            "upload_time_iso_8601": "2022-12-12T07:56:59.157560Z",
            "url": "https://files.pythonhosted.org/packages/fc/3b/52ddf5e003f21d25fa8eb5b3c3ff813465850b397c6f9e14140e2d1ef7b7/pgfusion-0.0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "md5": "34da8769d757f775d589c290ac81e04f",
                "sha256": "284a29d8fb3bcee6e239020489191c60617de12a1b45d50e299a4eee1ade1023"
            },
            "downloads": -1,
            "filename": "pgfusion-0.0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "34da8769d757f775d589c290ac81e04f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.4",
            "size": 4208,
            "upload_time": "2022-12-12T07:56:55",
            "upload_time_iso_8601": "2022-12-12T07:56:55.260941Z",
            "url": "https://files.pythonhosted.org/packages/fd/0e/8dba71f7df2ac127ec6acfb1a551cb7680c5276b669bb0a2c18cd70bd4c4/pgfusion-0.0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-12 07:56:55",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pgfusion"
}
        
Elapsed time: 0.02244s