{"id":19913620,"url":"https://github.com/255bits/pg-simple-auth","last_synced_at":"2026-04-12T16:03:57.245Z","repository":{"id":255925620,"uuid":"851411249","full_name":"255BITS/pg-simple-auth","owner":"255BITS","description":"A simple asynchronous authentication module for PostgreSQL","archived":false,"fork":false,"pushed_at":"2024-09-07T21:18:56.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-01T08:46:19.329Z","etag":null,"topics":["authentication","oauth","postgresql","python"],"latest_commit_sha":null,"homepage":null,"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/255BITS.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-03T03:43:44.000Z","updated_at":"2024-11-10T16:07:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"33654752-ba67-48e6-8fe4-09704323c958","html_url":"https://github.com/255BITS/pg-simple-auth","commit_stats":null,"previous_names":["255bits/pg-simple-auth"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/255BITS/pg-simple-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/255BITS%2Fpg-simple-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/255BITS%2Fpg-simple-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/255BITS%2Fpg-simple-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/255BITS%2Fpg-simple-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/255BITS","download_url":"https://codeload.github.com/255BITS/pg-simple-auth/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/255BITS%2Fpg-simple-auth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273753075,"owners_count":25161909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["authentication","oauth","postgresql","python"],"created_at":"2024-11-12T21:33:33.923Z","updated_at":"2026-04-12T16:03:57.192Z","avatar_url":"https://github.com/255BITS.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg_simple_auth\n\nA lightweight and easy-to-integrate authentication module for asynchronous Python applications using PostgreSQL and Quart. `pg_simple_auth` offers essential user authentication features such as signup, login, email verification, and password management, all built on secure and modern standards.\n\n## Features\n\n- **Asynchronous Design:** Fully asynchronous using `asyncio` and `asyncpg` to ensure non-blocking I/O operations.\n- **Seamless Integration:** Designed to work effortlessly with the Quart ASGI web framework.\n- **Secure Password Management:** Passwords are securely hashed using `argon2`, one of the most secure hashing algorithms available.\n- **JWT-Based Authentication:** Implements JSON Web Tokens (JWT) for stateless, secure user authentication.\n- **Built-in Email Verification:** Provides token-based email verification out of the box to ensure user identity.\n\npg_simple_auth lets you choose your framework, email sender, and app server while staying simple and easy to understand.\n\n## Installation\n\nInstall the necessary dependencies via pip:\n\n```sh\npip install pg_simple_auth\n```\n\n## Usage\n\n### Setting Up the Application\n\nIn your Quart application, initialize the `pg_simple_auth` module with the database configuration and secret key:\n\n```python\nfrom quart import Quart\nimport asyncpg\nimport pg_simple_auth as auth\n\napp = Quart(__name__)\n\nDATABASE_URL = \"postgresql://user:password@localhost/dbname\"\nSECRET_KEY = \"your_secret_key\"\nTABLE_NAME = \"users\"\n\n@app.before_serving\nasync def setup_db():\n    app.db_pool = await asyncpg.create_pool(DATABASE_URL)\n    await auth.initialize(app.db_pool, SECRET_KEY, TABLE_NAME)\n\n# Add your routes and other configurations\n\nif __name__ == '__main__':\n    app.secret_key = SECRET_KEY\n    app.run()\n```\n\n### Implementing Authentication Routes\n\nThe module provides easy-to-use methods for signup, login, and user session management:\n\n```python\n@app.route('/signup', methods=['POST'])\nasync def signup():\n    user = ...\n    password = ...\n    user_info = await auth.signup(user, password)\n    await auth.verify(user_info['verification_token'])\n    # auto verification, you may want to send an email here\n    ...\n\n@app.route('/login', methods=['POST'])\nasync def login():\n    user = ...\n    password = ...\n    await auth.login(user, password)\n    user_info = await auth.login(email, password)\n    if user_info:\n        session['token'] = user_info['token']\n    ...\n\n@app.route('/forgot_password', methods=['POST'])\nasync def forgot_password():\n    reset_token = await auth.forgot_password(email)\n    # generate an email with the reset_token\n\n@app.route('/change_password', methods=['GET', 'POST'])\nasync def change_password(token):\n    ...\n    if method == 'POST':\n        await auth.reset_password(token, new_password)\n    ...\n\n@app.route('/signout')\nasync def signout():\n    session.pop('token', None)\n    return redirect(url_for('login'))\n```\n\n### Example\n\nCheck the `examples/1-quart.py` file in this repository for a full example of how to set up and use `pg_simple_auth` in a Quart application.\n\n## Requirements\n\n- Python 3.8+\n- PostgreSQL 10+ (for proper `asyncpg` compatibility)\n- `asyncpg` library\n- `Quart` ASGI framework\n\n## Author\n\nDeveloped by [255labs.xyz](https://255labs.xyz), an AI product and consulting startup committed to helping people navigate the AI era through innovative products and open-source contributions.\n\n## Changelog\n\n* 09/03/24 - 0.1.1, add oauth support, `login_oauth(provider, oauth_id)` and `signup_oauth(provider, oauth_id, **insert_args)`\n\n## Contributing\n\nContributions are highly encouraged! Please open an issue to discuss potential changes or submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Acknowledgements\n\n- `asyncpg` for providing a robust asynchronous PostgreSQL driver.\n- The developers of `Quart` for creating an excellent ASGI framework for Python.\n- The PostgreSQL community for their powerful and reliable database system.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F255bits%2Fpg-simple-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F255bits%2Fpg-simple-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F255bits%2Fpg-simple-auth/lists"}