{"id":20114519,"url":"https://github.com/quantivio/pynotion","last_synced_at":"2025-05-06T12:31:10.749Z","repository":{"id":60770278,"uuid":"532993073","full_name":"Quantivio/PyNotion","owner":"Quantivio","description":"A Python library for simplified access to the Notion API, enabling easier integration and automation of Notion tasks in your Python projects.","archived":false,"fork":false,"pushed_at":"2024-08-05T02:13:58.000Z","size":750,"stargazers_count":15,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-07T23:55:11.106Z","etag":null,"topics":["notion","notion-api","notion-database","python","python3","requests"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/pynotionclient/","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/Quantivio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-09-05T17:15:16.000Z","updated_at":"2024-07-04T21:51:48.000Z","dependencies_parsed_at":"2024-10-26T02:34:27.538Z","dependency_job_id":"c7cb2bcf-009f-4e5f-a25a-d0cd28861df9","html_url":"https://github.com/Quantivio/PyNotion","commit_stats":null,"previous_names":["quantivio/pynotion"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantivio%2FPyNotion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantivio%2FPyNotion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantivio%2FPyNotion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quantivio%2FPyNotion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quantivio","download_url":"https://codeload.github.com/Quantivio/PyNotion/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224503557,"owners_count":17322227,"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":["notion","notion-api","notion-database","python","python3","requests"],"created_at":"2024-11-13T18:30:09.870Z","updated_at":"2024-11-13T18:30:11.143Z","avatar_url":"https://github.com/Quantivio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"assets/notion.png\" alt=\"Notion Logo\" height=\"240\" width=\"240\" style=\"display: block; margin-left: auto; margin-right: auto;\"\u003e\n\n# PyNotion\n\n\u003cdiv style=\"text-align: center;\"\u003e\n  \u003ca href=\"https://pypi.org/project/pynotionclient/\"\u003e\u003cimg alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/pynotionclient?color=brightgreen\u0026logo=pypi\u0026style=for-the-badge\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/pythonhubdev/PyNotion/commits/main\"\u003e\u003cimg alt=\"GitHub last commit\" src=\"https://img.shields.io/github/last-commit/pythonhubdev/PyNotion?style=for-the-badge\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/pythonhubdev/PyNotion/blob/main/LICENSE\"\u003e\u003cimg alt=\"GitHub license\" src=\"https://img.shields.io/github/license/pythonhubdev/PyNotion?color=brightgreen\u0026style=for-the-badge\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.python.org/\"\u003e\u003cimg alt=\"Static Badge\" src=\"https://img.shields.io/badge/Python-Lang?style=for-the-badge\u0026label=Made%20With%20%E2%9D%A4%EF%B8%8F\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\u003cp style=\"text-align: center;\"\u003e\n  PyNotion is a simple and intuitive Python library for accessing the Notion API. With PyNotion, you can easily integrate and automate Notion tasks within your Python projects.\n\u003c/p\u003e\n\n\u003cp style=\"text-align: center;\"\u003e\n  \u003cstrong\u003ePlease note that PyNotion is currently under development and may not yet be suitable for production use.\u003c/strong\u003e\n\u003c/p\u003e\n\n## Features\n\nPyNotion is currently in development and supports the following features:\n\n1. Create new databases\n2. Query existing databases\n\n## Installation\n\nYou can install PyNotion using either [Poetry](https://python-poetry.org/) or [pip](https://pypi.org/project/pip/).\n\n### Using Poetry\n\nTo install PyNotion using Poetry, run the following command in your terminal:\n\n```bash\npoetry add pynotionclient\n```\n\n### Using pip\n\nTo install PyNotion using pip, run the following command in your terminal:\n\n```bash\npip install pynotionclient\n```\n\n## Quick Start\n\n```python\nfrom src.py_notion import PyNotion\nfrom examples.config import base_config\nfrom src.py_notion.schema.database import RichTextFilter, PropertyFilter, Filter, NotionDatabaseResponseSchema\n\npy_notion_client = PyNotion(token=base_config.notion_secret_token)\n\n# Create necessary properties as dictionary\nfilter_dict = {\"page_size\": 100, \"filter\": {\"property\": \"Name\", \"rich_text\": {\"contains\": \"Home\"}}}\n\n# Create necessary filter objects from Pydantic models and use them to query the database.\n\nrich_text_filter = RichTextFilter(contains=\"Game\")\nproperty_filter = PropertyFilter(property=\"Name\", rich_text=rich_text_filter)\nfilter_object = Filter(page_size=100, filter=property_filter)\n\nresponse_dict_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(\n        database_id=base_config.database_id, payload=filter_dict\n)\nresponse_filter_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(\n        database_id=base_config.database_id, payload=filter_object\n)\n```\n\n## Querying a Database\n\n1. Querying a database using a dictionary\n\n```python\nfrom examples.config import base_config\nfrom src.py_notion import PyNotion\nfrom src.py_notion.schema.database import NotionDatabaseResponseSchema\n\npy_notion_client = PyNotion(token=base_config.notion_secret_token)\n\n# Create necessary properties as dictionary\nfilter_dict = {\"page_size\": 100, \"filter\": {\"property\": \"Name\", \"rich_text\": {\"contains\": \"Home\"}}}\nresponse_dict_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(\n database_id=base_config.database_id, payload=filter_dict\n)\n```\n\n2. Querying a database using a Pydantic model\n```python\nfrom examples.config import base_config\nfrom src.py_notion.schema.database import Filter, NotionDatabaseResponseSchema, PropertyFilter, RichTextFilter\nfrom src.py_notion import PyNotion\n\npy_notion_client = PyNotion(token=base_config.notion_secret_token)\n\n# Create necessary filter objects from Pydantic models and use them to query the database.\n\nrich_text_filter = RichTextFilter(contains=\"Game\")\nproperty_filter = PropertyFilter(property=\"Name\", rich_text=rich_text_filter)\nfilter_object = Filter(page_size=100, filter=property_filter)\n\nresponse_filter_payload: NotionDatabaseResponseSchema = py_notion_client.database.query_database(\n database_id=base_config.database_id, payload=filter_object)\n```\n\n    #### Response for querying a database\n    \u003e PyNotion client gives you the response as a Pydantic model. You can access the response as a dictionary or as a Pydantic model. The response is a NotionDatabaseResponseSchema model which has the following properties: https://developers.notion.com/reference/database\n\n3. Creating a Database\n\n```python\nfrom dotenv import load_dotenv\nfrom src.py_notion import PyNotion\nfrom examples.config import base_config\nfrom src.py_notion.schema.database import (\n  ParentConfiguration,\n  IconConfiguration,\n  TextConfiguration,\n  ExternalConfiguration,\n  CoverConfiguration,\n  SelectOptionsConfiguration,\n  SelectOptionsListConfig,\n  TitleConfiguration,\n  RichTextConfiguration,\n  CheckboxConfiguration,\n  SelectConfiguration,\n  ContentConfiguration,\n  MultiSelectConfiguration,\n  NumberConfiguration,\n  NumberFormats,\n  NumberFormatConfiguration,\n  DatabasePropertyConfiguration,\n)\n\nload_dotenv()\npy_notion_client = PyNotion(token=base_config.notion_secret_token)\n\n# # Create database payload\nparent_payload = ParentConfiguration(\n  type=\"page_id\", page_id=base_config.page_id\n)  # The parent is the page where the database will be created.\nicon_payload = IconConfiguration(\n  type=\"emoji\", emoji=\"🎮\"\n)  # The icon is the icon that will be displayed on the database.\ntext = TextConfiguration(\n  content=\"Game\"\n)  # The text is the text that will be displayed as the title of the database.\ncontent = ContentConfiguration(\n  type=\"text\", plain_text=\"Game\", href=\"https://www.google.com\", text=text\n)  # The content has other info's of the title.\n\n# Cover schema\ncover = CoverConfiguration(\n  type=\"external\", external=ExternalConfiguration(url=\"https://www.google.com\")\n)\n\n# # Forming select options schema\nproperties = {\n  \"Name\": TitleConfiguration().model_dump(),\n  \"Description\": RichTextConfiguration().model_dump(),\n  \"In stock\": CheckboxConfiguration().model_dump(),\n  \"Food Group\": SelectConfiguration(\n      select=SelectOptionsListConfig(\n          options=[\n              SelectOptionsConfiguration(color=\"green\", name=\"Code\"),\n              SelectOptionsConfiguration(color=\"red\", name=\"Game\"),\n          ],\n      )\n  ).model_dump(),\n  \"Cusines\": MultiSelectConfiguration(\n      multi_select=SelectOptionsListConfig(\n          options=[\n              SelectOptionsConfiguration(color=\"green\", name=\"Code\"),\n              SelectOptionsConfiguration(color=\"red\", name=\"Game\"),\n          ],\n      )\n  ).model_dump(),\n  \"Price\": NumberConfiguration(\n      number=NumberFormatConfiguration(\n          format=NumberFormats.NUMBER_WITH_COMMAS,\n      ),\n  ).model_dump(),\n}\nprint(properties)\ncreate_database_payload = DatabasePropertyConfiguration(\n  title=[content],\n  cover=cover,\n  parent=parent_payload,\n  icon=icon_payload,\n  properties=properties,\n)\n\nresponse = py_notion_client.database.create_database(\n  payload=create_database_payload,\n)\n\nprint(response.json())\n```\n\n\n# PyNotion Development Setup\nFollow these steps to set up your development environment for PyNotion:\n\n## Virtual Environment with Poetry\n1. Create a fork of the PyNotion repository\n2. Clone the repository to your local machine: `git clone git@github.com:\u003cusername\u003e/PyNotion.git`\n3. Install UV package manager based on your OS:\n      - Windows: powershell -c \"irm https://astral.sh/uv/install.ps1 | iex\"\n      - MacOS: curl -LsSf https://astral.sh/uv/install.sh | sh\n4. Navigate to the root of the project and run: `uv sync`\n\n## Pre-commit Hooks\n1. Install pre-commit hooks: `pre-commit install`\n2. Migrate pre-commit configurations: `pre-commit migrate-config`\n3. If you encounter an error, run: `git config --global --unset-all core.hooksPath or git config --unset-all core.hooksPath`\n\n## Contributing\nWe welcome contributions to PyNotion! Before making a major change, please open an issue to discuss your proposed changes. To submit a contribution, simply create a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantivio%2Fpynotion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquantivio%2Fpynotion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquantivio%2Fpynotion/lists"}