{"id":14974000,"url":"https://github.com/artsokolov/pgpython","last_synced_at":"2026-05-10T17:45:39.459Z","repository":{"id":57452168,"uuid":"189605505","full_name":"artsokolov/pgpython","owner":"artsokolov","description":"Python ORM for PostgreSQL","archived":false,"fork":false,"pushed_at":"2019-06-03T12:30:53.000Z","size":14,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-28T09:41:30.429Z","etag":null,"topics":["lib","library","orm","orm-library","orm-model","pg","pgsql","postgres","postgres-database","postgresql","postgresql-database","python","python3"],"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/artsokolov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-31T14:15:26.000Z","updated_at":"2025-08-27T12:20:17.000Z","dependencies_parsed_at":"2022-09-02T08:33:16.922Z","dependency_job_id":null,"html_url":"https://github.com/artsokolov/pgpython","commit_stats":null,"previous_names":["c0nder/pgpython"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/artsokolov/pgpython","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artsokolov%2Fpgpython","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artsokolov%2Fpgpython/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artsokolov%2Fpgpython/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artsokolov%2Fpgpython/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artsokolov","download_url":"https://codeload.github.com/artsokolov/pgpython/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artsokolov%2Fpgpython/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29868945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T18:42:30.764Z","status":"ssl_error","status_checked_at":"2026-02-26T18:41:47.936Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["lib","library","orm","orm-library","orm-model","pg","pgsql","postgres","postgres-database","postgresql","postgresql-database","python","python3"],"created_at":"2024-09-24T13:49:48.343Z","updated_at":"2026-02-26T19:41:54.275Z","avatar_url":"https://github.com/artsokolov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install pgpython.\n\n```bash\npip install pgpython\n```\n\n## Usage \n\n### Connect to database\n\nTo connect to the database you must create .env file in your directory with needed variables. Example:\n\n```python\nDB_NAME=testdb\nDB_USER=c0nder\nDB_HOST=localhost\nDB_PASSWORD=yourpassword\nDB_PORT=5432\n```\n\nAnd that's all you need to do!\n\n### Working with tables\n\nNext we are going to deal with tables. Imagine that you have got a table called **users** with next columns:\n  1. id (integer)\n  2. username (text)\n\nFirst, you have to import pgpython BaseModel to inherit your classes from it. Code:\n\n```python\nfrom pgpython import BaseModel\n```\n\nNext, you must import fields that you will use in your code. Fields must match up with you column type. Example:\n\n```python\nfrom pgpython.fields import IntegerField, StringField\n```\n\nThere are 4 types in total: **IntegerField, DateField, JSONField, StringField**\n\nNext, you must create a class called as your table name with attributes called as your columns. Code:\n\n```python\nclass users(BaseModel):\n  id = IntegerField()\n  username = StringField()\n```\n\nThat's is all you need to tie up your class and table.\n\n### methods\n\n#### Insert data\n\nAfter creating a class you must create an object of this class. Using our example of users table let's code:\n\n\n```python\nuser = users()\n```\n\nNext, let's set our data to an object.\n\n**IMPORTANT** If you have an auto_incremented id than you must not to set id to your object.\n\n\n```python\nuser.id = 1\nuser.username = 'c0nder'\n```\n\nThen, use method add()\n\n```python\nuser.add()\n```\n\nThat's all!\n\n#### Selecting data from table\n\nAt first, you must, as always, create an object and set data that you need to use to select data from table. Than use method select() to select data.\n\n```python\nuser = users()\nuser.username = 'c0nder'\ndata = user.selectBy({'username': user.username})\n```\n\n#### Load object by id\n\n```python\nuser = users.loadById(1)\n```\n\n#### Updating data\n\n```python\nuser = users.loadById(1)\nuser.username = 'New_username'\nuser.update()\n```\n\n#### Delete data\n\n```python\nuser = users.loadById(1)\nuser.delete()\n```\n\n#### Getting columns of table object\n\n\n```python\nuser = users.loadById(1)\ncolumns = user.getColumns()\n\nfor col, obj in columns.items():\n\tprint(col, \":\", obj.value)\n```\n\n#### Printing value of object attribute\n\n```python\nuser = users.loadById(1)\nprint(user.username.value)\n```\n\n### Working with Schemas\n\nTo work with schemas you need to import BaseSchema.\n\n```python\nfrom pgpython import BaseModel, BaseSchema\n```\n\nNext, we will use our table users.\n\n```python\nclass users(BaseModel):\n  id = IntegerField()\n  username = StringField()\n```\n\nThan, you need to create schema class.\n\n```python\nclass schema_name(BaseSchema):\n  users = users()\n```\nExample of using:\n\n```python\nuser = schema_name.users.loadById(1)\n```\n\nThat's all!\n\u003e\u003e\u003e\u003e\u003e\u003e\u003e Added ReadMe\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartsokolov%2Fpgpython","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartsokolov%2Fpgpython","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartsokolov%2Fpgpython/lists"}