fastpg


Namefastpg JSON
Version 0.0.6 PyPI version JSON
download
home_pageNone
SummaryA fast Postgres client library for Python
upload_time2023-06-26 14:41:17
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.
            # fastpg

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

A fast Postgres client library for Python.

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

## Installation

```bash
$ pip install fastpg
```

## Quickstart

```python
from fastpg 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": "fastpg",
    "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/97/7f/cc61050507f544a9e2fa80843f3f70c56ab1479afa5876a43a2f31aa2d88/fastpg-0.0.6.tar.gz",
    "platform": null,
    "description": "# fastpg\n\n[![PyPI version](https://badge.fury.io/py/fastpg.svg)](https://pypi.org/project/fastpg/)\n\nA fast Postgres client library for Python.\n\nThe only dependency for **fastpg** is [asyncpg](https://github.com/MagicStack/asyncpg),\nand the api wrapper is very similar to the api provided by the\n[databases](https://github.com/encode/databases) package.\n\n## Installation\n\n```bash\n$ pip install fastpg\n```\n\n## Quickstart\n\n```python\nfrom fastpg 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": "A fast Postgres client library for Python",
    "version": "0.0.6",
    "project_urls": {
        "Homepage": "https://github.com/waydegg/fastpg",
        "Source": "https://github.com/waydegg/fastpg"
    },
    "split_keywords": [
        "asyncio",
        "asyncpg",
        "postgres",
        "python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4aa8e42d373d0c856bed073c509fddcfb590c4ebf18fa3d15c232d9e6bd3909f",
                "md5": "227bc8f5dcc4acfcf65a5ccbf3d70ae8",
                "sha256": "13251d255ad176270ad274d551e595d98577def68516c913c0205e07e2e28f44"
            },
            "downloads": -1,
            "filename": "fastpg-0.0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "227bc8f5dcc4acfcf65a5ccbf3d70ae8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10.4",
            "size": 5665,
            "upload_time": "2023-06-26T14:41:14",
            "upload_time_iso_8601": "2023-06-26T14:41:14.893956Z",
            "url": "https://files.pythonhosted.org/packages/4a/a8/e42d373d0c856bed073c509fddcfb590c4ebf18fa3d15c232d9e6bd3909f/fastpg-0.0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "977fcc61050507f544a9e2fa80843f3f70c56ab1479afa5876a43a2f31aa2d88",
                "md5": "3fda90dba50505d65f6995dca54f8719",
                "sha256": "91127b92d7098803e543b77d1cbb76946e6360845e3064e7a0fbb0cde005b7b2"
            },
            "downloads": -1,
            "filename": "fastpg-0.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "3fda90dba50505d65f6995dca54f8719",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.4",
            "size": 4914,
            "upload_time": "2023-06-26T14:41:17",
            "upload_time_iso_8601": "2023-06-26T14:41:17.048318Z",
            "url": "https://files.pythonhosted.org/packages/97/7f/cc61050507f544a9e2fa80843f3f70c56ab1479afa5876a43a2f31aa2d88/fastpg-0.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-26 14:41:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "waydegg",
    "github_project": "fastpg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastpg"
}
        
Elapsed time: 0.95573s