| Name | pyconnpg JSON | 
            
| Version | 
                  1.3.1
                   
                  JSON | 
            
 | download  | 
            
| home_page | None  | 
            
| Summary | A simplified Python library for PostgreSQL CRUD operations. | 
            | upload_time | 2025-11-02 03:59:53 | 
            | maintainer | None | 
            
            | docs_url | None | 
            | author | None | 
            
            | requires_python | >=3.10 | 
            
            
            | license | None | 
            | keywords | 
                
                    postgresql
                
                     database
                
                     connection
                 | 
            | VCS | 
                
                    | 
                
            
            | bugtrack_url | 
                
                 | 
             
            
            | requirements | 
                
                  No requirements were recorded.
                
             | 
            
| Travis-CI | 
                
                   No Travis.
                
             | 
            | coveralls test coverage | 
                
                   No coveralls.
                
             | 
        
        
            
            # PostgreSQL Connection Helper
A lightweight Python utility class for connecting to PostgreSQL databases, executing CRUD operations, and performing common table actions (insert, update, delete, add column, etc.).
Supports environment variable configuration.
## 🚀 Features:
* Connect easily to PostgreSQL using direct arguments or environment variables
* Insert single or multiple rows
* Batch inserts using execute_values for high performance
* Conditional inserts with conflict checks (ON CONFLICT DO NOTHING)
* Table maintenance utilities (add columns, update rows, delete rows)
* Check for record existence (check_exists, check_exists_long)
* Fetch specific column values based on conditions
* Clean and explicit API for common database actions
## ⚙️ Usage
1. Basic Connection
    ```python
    import pyconnpg 
    db = pyconnpg.Connect(
        host='hostname or IP',
        port=5432,
        db='mydatabase',
        user='myuser',
        password='mypassword'
    )
    ```
2. Using Environment Variables
    You can define these variables in your shell or home directory .pgenv file or load your env file using dotenv:
    | Variable    | Description                 |
    | ----------- | --------------------------- |
    | `PG_HOST`   | PostgreSQL host             |
    | `PG_PORT`   | PostgreSQL port             |
    | `PG_DB`     | Database name               |
    | `PG_USER`   | Database username           |
    | `PG_PASSWD` | Database password |
    Then, simply initialize:
    ```python
    import pyconnpg
    db = pyconnpg.Connect()
    ```
## 🧪 Example Workflow
### 1. `check_exists(column_name: str, find) -> bool` 
Checks if a record exists in the table.
```python
# Example
exists = db.check_exists(column_name='user_id', find='U001')
print(exists)  # True or False
```
### 2. `check_exists_long(where: str) -> bool` 
Checks record existence using complex WHERE clauses.
```python
# Example
exists = db.check_exists_long("user_id='U001' AND status='active'")
```
### 3. `insert(**kwargs)` 
Inserts a single row into the connected table.
```python
# Example
db.insert(product='Widget', version=3)
```
### 4. `batch_insert(data: list[dict]) -> bool`
Batch insert using efficient execute_values.
```python
# Example
records = [
    {"id": "2025-10-21_1", "date": "2025-10-21", "users": "user1", "usage": 3},
    {"id": "2025-10-21_2", "date": "2025-10-21", "users": "user2", "usage": 5}
]
db.batch_insert(records)
```
### 5. `insert_many(data: list[dict]) -> bool`
Batch insert using standard executemany.
```python
# Example
records = [
    {"id": "2025-10-21_1", "date": "2025-10-21", "users": "user1", "usage": 3},
    {"id": "2025-10-21_2", "date": "2025-10-21", "users": "user2", "usage": 5}
]
db.insert_many(records)
```
### 6. `insert_with_conflict_check(check_conflict, **kwargs)`
Inserts a record but ignores duplicates on conflict.\
`check_conflict`: column name of the primary key or unique constraint.
```python
# Example
db.insert_with_conflict_check(
    check_conflict='id',
    product='Gizmo',
    version=2
)
```
### 7. `update_row(column_name: str, value, where: str)`
Updates a row matching a condition.
```python
# Example
db.update_row(column_name='version', value=4, where="id='2025-10-21_1'")
```
### 8. `add_column(column_name: str, col_type: str)`
Adds a new column if it does not exist.
```python
# Example
db.add_column(column_name='last_login', col_type='timestamp')
```
### 9. `get_value_match(column_name: str, where_column: str, match: str) -> str`
Fetches a specific value when a condition matches.
```python
# Example
email = db.get_value_match('email', 'username', 'john_doe')
print(email)
```
### 10. `delete_row(condition: str)`
Deletes rows that satisfy the given condition.
```python
# Example
db.delete_row("user_id='U001'")
```
### 11. close() -> None
Closes the PostgreSQL connection.
```python
# Example
db.close()
```
## 🧱 Requirements
* Python ≥ 3.10+
* PostgreSQL ≥ 13
* psycopg2
* cryptography
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": null,
    "name": "pyconnpg",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "postgresql, database, connection",
    "author": null,
    "author_email": "Josephus <no-reply@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/8a/23/65d55892d83d0c279bdd02ebf59e77a95c3b920a7ff3820ed51225eec02f/pyconnpg-1.3.1.tar.gz",
    "platform": null,
    "description": "# PostgreSQL Connection Helper\r\n\r\nA lightweight Python utility class for connecting to PostgreSQL databases, executing CRUD operations, and performing common table actions (insert, update, delete, add column, etc.).\r\nSupports environment variable configuration.\r\n\r\n\r\n\r\n## \ud83d\ude80 Features:\r\n\r\n* Connect easily to PostgreSQL using direct arguments or environment variables\r\n\r\n* Insert single or multiple rows\r\n\r\n* Batch inserts using execute_values for high performance\r\n\r\n* Conditional inserts with conflict checks (ON CONFLICT DO NOTHING)\r\n\r\n* Table maintenance utilities (add columns, update rows, delete rows)\r\n\r\n* Check for record existence (check_exists, check_exists_long)\r\n\r\n* Fetch specific column values based on conditions\r\n\r\n* Clean and explicit API for common database actions\r\n\r\n\r\n## \u2699\ufe0f Usage\r\n1. Basic Connection\r\n    ```python\r\n    import pyconnpg \r\n\r\n    db = pyconnpg.Connect(\r\n        host='hostname or IP',\r\n        port=5432,\r\n        db='mydatabase',\r\n        user='myuser',\r\n        password='mypassword'\r\n    )\r\n    ```\r\n\r\n2. Using Environment Variables\r\n\r\n    You can define these variables in your shell or home directory .pgenv file or load your env file using dotenv:\r\n    | Variable    | Description                 |\r\n    | ----------- | --------------------------- |\r\n    | `PG_HOST`   | PostgreSQL host             |\r\n    | `PG_PORT`   | PostgreSQL port             |\r\n    | `PG_DB`     | Database name               |\r\n    | `PG_USER`   | Database username           |\r\n    | `PG_PASSWD` | Database password |\r\n\r\n\r\n    Then, simply initialize:\r\n    ```python\r\n    import pyconnpg\r\n    db = pyconnpg.Connect()\r\n    ```\r\n\r\n## \ud83e\uddea Example Workflow\r\n### 1. `check_exists(column_name: str, find) -> bool` \r\nChecks if a record exists in the table.\r\n```python\r\n# Example\r\nexists = db.check_exists(column_name='user_id', find='U001')\r\nprint(exists)  # True or False\r\n```\r\n### 2. `check_exists_long(where: str) -> bool` \r\nChecks record existence using complex WHERE clauses.\r\n```python\r\n# Example\r\nexists = db.check_exists_long(\"user_id='U001' AND status='active'\")\r\n```\r\n\r\n### 3. `insert(**kwargs)` \r\nInserts a single row into the connected table.\r\n```python\r\n# Example\r\ndb.insert(product='Widget', version=3)\r\n```\r\n\r\n### 4. `batch_insert(data: list[dict]) -> bool`\r\nBatch insert using efficient execute_values.\r\n```python\r\n# Example\r\nrecords = [\r\n    {\"id\": \"2025-10-21_1\", \"date\": \"2025-10-21\", \"users\": \"user1\", \"usage\": 3},\r\n    {\"id\": \"2025-10-21_2\", \"date\": \"2025-10-21\", \"users\": \"user2\", \"usage\": 5}\r\n]\r\ndb.batch_insert(records)\r\n```\r\n\r\n### 5. `insert_many(data: list[dict]) -> bool`\r\nBatch insert using standard executemany.\r\n```python\r\n# Example\r\nrecords = [\r\n    {\"id\": \"2025-10-21_1\", \"date\": \"2025-10-21\", \"users\": \"user1\", \"usage\": 3},\r\n    {\"id\": \"2025-10-21_2\", \"date\": \"2025-10-21\", \"users\": \"user2\", \"usage\": 5}\r\n]\r\ndb.insert_many(records)\r\n```\r\n\r\n### 6. `insert_with_conflict_check(check_conflict, **kwargs)`\r\nInserts a record but ignores duplicates on conflict.\\\r\n`check_conflict`: column name of the primary key or unique constraint.\r\n```python\r\n# Example\r\ndb.insert_with_conflict_check(\r\n    check_conflict='id',\r\n    product='Gizmo',\r\n    version=2\r\n)\r\n```\r\n\r\n### 7. `update_row(column_name: str, value, where: str)`\r\nUpdates a row matching a condition.\r\n```python\r\n# Example\r\ndb.update_row(column_name='version', value=4, where=\"id='2025-10-21_1'\")\r\n```\r\n\r\n### 8. `add_column(column_name: str, col_type: str)`\r\nAdds a new column if it does not exist.\r\n```python\r\n# Example\r\ndb.add_column(column_name='last_login', col_type='timestamp')\r\n```\r\n\r\n### 9. `get_value_match(column_name: str, where_column: str, match: str) -> str`\r\nFetches a specific value when a condition matches.\r\n```python\r\n# Example\r\nemail = db.get_value_match('email', 'username', 'john_doe')\r\nprint(email)\r\n```\r\n### 10. `delete_row(condition: str)`\r\nDeletes rows that satisfy the given condition.\r\n```python\r\n# Example\r\ndb.delete_row(\"user_id='U001'\")\r\n```\r\n\r\n### 11. close() -> None\r\nCloses the PostgreSQL connection.\r\n\r\n```python\r\n# Example\r\ndb.close()\r\n```\r\n\r\n\r\n\r\n## \ud83e\uddf1 Requirements\r\n\r\n* Python \u2265 3.10+\r\n\r\n* PostgreSQL \u2265 13\r\n\r\n* psycopg2\r\n\r\n* cryptography\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A simplified Python library for PostgreSQL CRUD operations.",
    "version": "1.3.1",
    "project_urls": null,
    "split_keywords": [
        "postgresql",
        " database",
        " connection"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "238b71f1adcd67789b72cbb6fb3430f8be7a161c7d44f7a2d261a7e9e7d6e7c7",
                "md5": "16c28383ecebd2596a557eb0e375fe3a",
                "sha256": "412c0e65657aac31873f009fb9a9321f5dca83c73bb2e79d244c82ca7682645a"
            },
            "downloads": -1,
            "filename": "pyconnpg-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "16c28383ecebd2596a557eb0e375fe3a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6210,
            "upload_time": "2025-11-02T03:59:52",
            "upload_time_iso_8601": "2025-11-02T03:59:52.009484Z",
            "url": "https://files.pythonhosted.org/packages/23/8b/71f1adcd67789b72cbb6fb3430f8be7a161c7d44f7a2d261a7e9e7d6e7c7/pyconnpg-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8a2365d55892d83d0c279bdd02ebf59e77a95c3b920a7ff3820ed51225eec02f",
                "md5": "d41fa95d2ebeb4e74af3c117dfe4e2be",
                "sha256": "d55fcf84f50f4b9444776556ee6c448fa23b83ae049cdefbe5f9439e00c2882a"
            },
            "downloads": -1,
            "filename": "pyconnpg-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d41fa95d2ebeb4e74af3c117dfe4e2be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 7072,
            "upload_time": "2025-11-02T03:59:53",
            "upload_time_iso_8601": "2025-11-02T03:59:53.350119Z",
            "url": "https://files.pythonhosted.org/packages/8a/23/65d55892d83d0c279bdd02ebf59e77a95c3b920a7ff3820ed51225eec02f/pyconnpg-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-02 03:59:53",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pyconnpg"
}