{"id":20391103,"url":"https://github.com/aditya76-git/pynotiondb","last_synced_at":"2025-04-12T11:22:26.963Z","repository":{"id":238671271,"uuid":"797193446","full_name":"aditya76-git/pynotiondb","owner":"aditya76-git","description":"A Python wrapper for interacting with Notion databases using SQL-style syntax","archived":false,"fork":false,"pushed_at":"2024-07-27T18:58:44.000Z","size":105,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T06:11:22.480Z","etag":null,"topics":[],"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/aditya76-git.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-05-07T11:26:37.000Z","updated_at":"2024-08-21T10:57:24.000Z","dependencies_parsed_at":"2024-06-06T19:31:35.094Z","dependency_job_id":"f6931ad8-fe77-4d0e-b89e-9bdffbc54938","html_url":"https://github.com/aditya76-git/pynotiondb","commit_stats":null,"previous_names":["aditya76-git/pynotiondb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya76-git%2Fpynotiondb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya76-git%2Fpynotiondb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya76-git%2Fpynotiondb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aditya76-git%2Fpynotiondb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aditya76-git","download_url":"https://codeload.github.com/aditya76-git/pynotiondb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248558306,"owners_count":21124250,"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","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":[],"created_at":"2024-11-15T03:28:48.616Z","updated_at":"2025-04-12T11:22:26.930Z","avatar_url":"https://github.com/aditya76-git.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003epynotiondb\u003c/h1\u003e\r\n\u003cp align=\"center\"\u003e\r\n    \u003cimg src=\"https://i.imgur.com/Vv7q65D.png\" alt=\"pynotiondb\"\u003e\r\n\u003c/p\u003e\r\n\r\n\u003ch4 align=\"center\"\u003e\r\nA Python wrapper for interacting with Notion databases using SQL-style syntax\u003c/h4\u003e\r\n\r\n\u003cdiv style=\"text-align:center;\"\u003e\r\n  \u003ca href=\"https://github.com/aditya76-git\"\u003eaditya76-git\u003c/a\u003e /\r\n  \u003ca href=\"https://github.com/aditya76-git/pynotiondb\"\u003epynotiondb\u003c/a\u003e\r\n\u003c/div\u003e\r\n\r\n\u003cbr /\u003e\r\n\r\n# pynotiondb\r\n\r\n`pynotiondb` is a Python package that provides a convenient way to interact with Notion databases using SQL-style syntax.\r\n\r\n## 📋Details\r\n\r\n- ➕ [Insert Statement](#insert)\r\n  - [Single-Row Insertion](#single-row-insertion)\r\n  - [Multiple-Row Insertion](#multiple-row-insertion)\r\n- 🔎 [Select Statement](#select)\r\n  - [Default Retrieval with All Columns](#default-retrieval-with-all-columns)\r\n  - [Retrieval with Specified Columns](#retrieval-with-specified-columns)\r\n  - [Retrieval with Specified Columns and Custom Page Size](#retrieval-with-specified-columns-and-custom-page-size)\r\n  - [Applying Conditions](#applying-conditions)\r\n  - [Applying Conditions (2)](#applying-conditions-2)\r\n- ⚡ [Update Statement](#update)\r\n  - [Updating a row](#updating-a-row)\r\n- ⚡ [Delete Statement](#delete)\r\n  - [Deleting a row](#single-row-deletion)\r\n\r\n## ⚙️Installation\r\n\r\nOpen your terminal or command prompt and enter the following command:\r\n\r\n```bash\r\npip install git+https://github.com/aditya76-git/pynotiondb@main\r\n```\r\n\r\n\u003e **Note:** To use this package you need to have a Active Notion Account\r\n\r\n## 🚀Pre-requisites\r\n\r\nBefore using this package, you'll need to set up a few things in your Notion workspace:\r\n\r\n1. **Create an Integration in Notion**: Begin by creating a new integration in Notion’s integrations dashboard: [https://www.notion.com/my-integrations](https://www.notion.com/my-integrations).\r\n   \u003cbr/\u003e\r\n   [DOCS](https://developers.notion.com/docs/create-a-notion-integration)\r\n\r\n2. **Obtain Your API Secret**: API requests require an API secret to be successfully authenticated. Visit the `Secrets` tab to get your integration’s API secret\r\n\r\n3. **Get the Database ID**: Retrieve the database ID from the URL of your Notion database.\r\n\r\n\u003e For example, in the URL `https://www.notion.so/f30ed4836a234308a63f7b76f71b098c?v=f9adf71ce9924344bf01e072150436cb`, `f30ed4836a234308a63f7b76f71b098c` is the database ID\r\n\r\n4. **Connect the Integration to the Database**: Connect your database to the integration by clicking on the three dots menu, navigating to the connections tab, and selecting your integration from the available options.\r\n\r\n## 📌 Note\r\n\r\n- To utilize this package, you'll initially need to create a database or table within Notion. Customize the table headers to align with your requirements; for instance, if you're managing customer data, you'd include headers such as \"Name\" and \"Address\" as needed.\r\n\r\n- When adding a new table header in the database, ensure to select \"Text\" or Number from the Type dropdown menu. This selection ensures that the data is stored as text or as number, which is compatible with the package's functionality for retrieving rows. Avoid selecting any other options from the dropdown menu.\r\n\r\n- As of now, the `pynotiondb` package only supports `INSERT` and `SELECT` statements. It does not offer functionalities to create tables or add table headers directly from the package itself. Therefore, users must manually create the tables with appropriate headers in Notion before using the package.\r\n\r\n- Even if you mistakenly input an incorrect table name while executing SQL statements, the query will still execute successfully due to the databaseId being used when you do `mydb = NOTION_API(\"API_SECRET\", \"DATABASE_ID\")`.\r\n\r\n- Additional statements will be implemented in future updates of the package.\r\n\r\n## 📷 Notion Database View\r\n\r\n\u003cp align=\"center\"\u003e\r\n    \u003cimg src=\"https://i.imgur.com/NT580RY.png\" alt=\"Notion Database Web View\"\u003e\r\n\u003c/p\u003e\r\n\r\n## 🚀Initialization\r\n\r\n```python3\r\nfrom pynotiondb import NOTION_API\r\nmydb = NOTION_API(\"API_SECRET\", \"DATABASE_ID\")\r\n```\r\n\r\n## \u003ca id=\"insert\"\u003e\u003c/a\u003e➕ `INSERT` Statement\r\n\r\n#### \u003ca id=\"single-row-insertion\"\u003e\u003c/a\u003e➡️ Single-Row Insertion\r\n\r\nTo insert a single row into the table:\r\n\r\n```python3\r\nsql = \"INSERT INTO employees (name, address) VALUES (%s, %s)\"\r\nval = (\"John\", \"Highway 21\")\r\nmydb.execute(sql, val)\r\n```\r\n\r\n#### \u003ca id=\"multiple-row-insertion\"\u003e\u003c/a\u003e➡️ Multiple-Row Insertion\r\n\r\nTo insert a single row into the table:\r\n\r\n```python3\r\nsql = \"INSERT INTO employees (name, address) VALUES (%s, %s)\"\r\nval = [\r\n    (\"John\", \"Highway 21\"),\r\n    (\"Lilly\", \"Road 99\"),\r\n]\r\nmydb.execute(sql, val)\r\n\r\n```\r\n\r\n## \u003ca id=\"select\"\u003e\u003c/a\u003e🔎 `SELECT` Statement\r\n\r\n#### \u003ca id=\"default-retrieval-with-all-columns\"\u003e\u003c/a\u003e➡️ Default Retrieval with All Columns\r\n\r\nTo fetch data from the database with all columns and a default page size of 20:\r\n\r\n```python3\r\nsql = \"SELECT * FROM employees\"\r\ndata = mydb.execute(sql)\r\n```\r\n\r\n- This query retrieves all rows and columns from the employees table.\r\n- The default page size is set to 20 rows.\r\n\r\n- Returned data includes all columns such as `name`, `address`, and `salary`.\r\n\r\n```json\r\n{\r\n  \"data\": [\r\n    {\r\n      \"address\": \"Highway 21\",\r\n      \"salary\": 1000,\r\n      \"name\": \"John\"\r\n    },\r\n    {\r\n      \"address\": \"Highway 21\",\r\n      \"salary\": 2000,\r\n      \"name\": \"John\"\r\n    }\r\n  ],\r\n  \"next_cursor\": null,\r\n  \"previous_cursor\": null,\r\n  \"has_more\": false\r\n}\r\n```\r\n\r\n#### \u003ca id=\"retrieval-with-specified-columns\"\u003e\u003c/a\u003e➡️ Retrieval with Specified Columns\r\n\r\nTo fetch data with specific columns:\r\n\r\n```python3\r\nsql = \"SELECT name, address FROM employees\"\r\ndata = mydb.execute(sql)\r\n\r\n```\r\n\r\n- This query retrieves only the `name` and `address` columns from the employees table.\r\n\r\n- The default page size is set to 20 rows.\r\n\r\n```json\r\n{\r\n  \"data\": [\r\n    {\r\n      \"address\": \"Highway 21\",\r\n      \"name\": \"John\"\r\n    },\r\n    {\r\n      \"address\": \"Highway 21\",\r\n      \"name\": \"John\"\r\n    }\r\n  ],\r\n  \"next_cursor\": null,\r\n  \"previous_cursor\": null,\r\n  \"has_more\": false\r\n}\r\n```\r\n\r\n#### \u003ca id=\"retrieval-with-specified-columns-and-custom-page-size\"\u003e\u003c/a\u003e➡️ Retrieval with Specified Columns and Custom Page Size\r\n\r\nTo fetch data with specific columns:\r\n\r\n```python3\r\nsql = \"SELECT name, address FROM employees WHERE page_size = 1\"\r\ndata = mydb.execute(sql)\r\n```\r\n\r\n```python3\r\nsql = \"SELECT * FROM employees WHERE page_size = 1\"\r\ndata = mydb.execute(sql)\r\n```\r\n\r\n- This query retrieves only the `name` and `address` columns from the employees table.\r\n- Adding `*` will select all the colums\r\n\r\n- The page_size parameter allows customization of the number of rows returned per page.\r\n\r\n```json\r\n{\r\n  \"data\": [\r\n    {\r\n      \"name\": \"John\",\r\n      \"address\": \"Highway 21\"\r\n    }\r\n  ],\r\n  \"next_cursor\": \"7184fff3-8859-45a1-863b-ab5c0d403a45\",\r\n  \"previous_cursor\": null,\r\n  \"has_more\": true\r\n}\r\n```\r\n\r\n#### \u003ca id=\"applying-conditions\"\u003e\u003c/a\u003e➡️ Applying Conditions\r\n\r\nTo apply conditions for data retrieval, such as filtering based on numeric values:\r\n\r\n```python3\r\nsql = \"SELECT * FROM employees WHERE salary \u003e 1000\"\r\ndata = mydb.execute(sql)\r\n\r\n```\r\n\r\n- This query retrieves all columns from the employees table where the `salary` is greater than 1000.\r\n\r\n- Only numeric columns can be used for numerical comparisons.\r\n\r\n- Make sure the property you are applying conditions for has a Number type in the Notion Database\r\n\r\n```json\r\n{\r\n  \"data\": [\r\n    {\r\n      \"address\": \"Highway 21\",\r\n      \"salary\": 1291029102910219,\r\n      \"name\": \"John\"\r\n    },\r\n    {\r\n      \"address\": \"Some Road\",\r\n      \"salary\": 10000000,\r\n      \"name\": \"Aditya\"\r\n    }\r\n  ],\r\n  \"next_cursor\": null,\r\n  \"previous_cursor\": null,\r\n  \"has_more\": false\r\n}\r\n```\r\n\r\n#### \u003ca id=\"applying-conditions-2\"\u003e\u003c/a\u003e➡️ Applying Conditions (2)\r\n\r\nTo apply conditions for data retrieval, such as filtering based on numeric values:\r\n\r\n```python3\r\nsql = \"SELECT * FROM employees WHERE salary \u003e 1000 AND name = 'John' and page_size = 10\"\r\ndata = mydb.execute(sql)\r\n\r\n```\r\n\r\n- This query retrieves all columns from the employees table where the `salary` is greater than 1000 and name which is John and page_size of 10.\r\n\r\n- Only numeric columns can be used for numerical comparisons.\r\n\r\n- Make sure the property you are applying conditions for has a Number type in the Notion Database\r\n\r\n```json\r\n{\r\n  \"data\": [\r\n    {\r\n      \"address\": \"Highway 21\",\r\n      \"salary\": 1291029102910219,\r\n      \"name\": \"John\"\r\n    },\r\n    {\r\n      \"address\": \"Some Road\",\r\n      \"salary\": 10000000,\r\n      \"name\": \"Aditya\"\r\n    }\r\n  ],\r\n  \"next_cursor\": null,\r\n  \"previous_cursor\": null,\r\n  \"has_more\": false\r\n}\r\n```\r\n\r\n## \u003ca id=\"update\"\u003e\u003c/a\u003e⚡ `UPDATE` Statement\r\n\r\n#### \u003ca id=\"updating-a-row\"\u003e\u003c/a\u003e➡️ Updating a Row\r\n\r\nTo update a single row into the table:\r\n\r\n```python3\r\nsql = \"UPDATE employees SET salary = 20000 WHERE name = Rachel Adams\"\r\nsql = \"UPDATE employees SET salary = 20000 WHERE name = 'Rachel Adams'\"\r\nmydb.execute(sql)\r\n```\r\n\r\n- This query will update the salary to 20000 for the row with the name 'Rachel Adams'.\r\n- Using single quotes around the name is recommended, especially if the value contains spaces or special characters.\r\n\r\n## \u003ca id=\"delete\"\u003e\u003c/a\u003e➕ `DELETE` Statement\r\n\r\n#### \u003ca id=\"single-row-deletion\"\u003e\u003c/a\u003e➡️ Single-Row Deletion\r\n\r\nTo delete a single row into the table:\r\n\r\n```python3\r\nsql = \"DELETE FROM employees WHERE salary \u003c 110\"\r\nmydb.execute(sql)\r\n```\r\n\r\n## 🌟 Show Your Support\r\n\r\n- If you find this project useful or interesting, please consider giving it a star on GitHub. It's a simple way to show your support and help others discover the project.\r\n\r\n![Github Stars](https://img.shields.io/github/stars/aditya76-git/pynotiondb?style=social \"Github Stars\")\r\n\r\n## 👨‍💻Developement\r\n\r\nThank you for your interest in contributing to this project! There are several ways you can get involved:\r\n\r\n- **Opening Issues**: If you encounter a bug, have a feature request, or want to suggest an improvement, please open an issue. We appreciate your feedback!\r\n- **Cloning the Project**: To work on the project locally, you can clone the repository by running:\r\n\r\n```bash\r\ngit clone https://github.com/aditya76-git/pynotiondb.git\r\n```\r\n\r\n- **Sending Pull Requests**: If you'd like to contribute directly to the codebase, you can fork the repository, make your changes, and then send a pull request. We welcome your contributions!\r\n\r\n## 💻Authors\r\n\r\n- Copyright © 2024 - [aditya76-git](https://github.com/aditya76-git) / [pynotiondb](https://github.com/aditya76-git/pynotiondb)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faditya76-git%2Fpynotiondb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faditya76-git%2Fpynotiondb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faditya76-git%2Fpynotiondb/lists"}