Contributing¶
Welcome to the contributor guide of Ultimate Notion.
This document focuses on getting any potential contributor familiarized with the development processes, but other kinds of contributions are also appreciated.
If you are new to using git or have never collaborated on a project previously, please have a look at contribution-guide.org. Other resources are also listed in the excellent guide created by FreeCodeCamp 1.
Please notice that all users and contributors are expected to be open, considerate, reasonable, and respectful. When in doubt, Python Software Foundation's Code of Conduct is a good reference in terms of behavior guidelines.
Issue Reports¶
If you experience bugs or general issues with Ultimate Notion, please have a look at the issue tracker. If you don't see anything useful there, please feel free to file an issue report.
Tip
Please don't forget to include the closed issues in your search. Sometimes a solution was already reported, and the problem is considered solved.
New issue reports should include information about your programming environment (e.g., operating system, Python version) and steps to reproduce the problem. Please also try to simplify the reproduction steps to a very minimal example that still illustrates the problem you are facing. By removing other factors, you help us to identify the root cause of the issue.
Documentation improvements¶
You can help improve the documentation of Ultimate Notion by making them more readable and coherent, or by adding missing information and correcting mistakes.
This documentation uses mkdocs as its main documentation compiler. This means that the docs are kept in the same repository as the project code, and that any documentation update is done in the same way as a code contribution.
Tip
Please notice that the GitHub web interface provides a quick way for proposing changes. While this mechanism can be tricky for normal code contributions, it works perfectly fine for contributing to the docs, and can be quite handy. If you are interested in trying this method out, please navigate to the docs folder in the source repository, find which file you would like to propose changes to and click on the little pencil icon at the top, to open GitHub's code editor. Once you finish editing the file, please write a message in the form at the bottom of the page describing which changes you have made and what the motivations behind them are and submit your proposal.
When working on documentation changes in your local machine, you can build and serve them using hatch with hatch run docs:build and hatch run docs:serve, respectively.
Code Contributions¶
Submit an issue¶
Before you work on any non-trivial code contribution it's best to first create a report in the issue tracker to start a discussion on the subject. This often provides additional considerations and avoids unnecessary work.
Clone the repository¶
-
Create a user account on GitHub if you do not already have one.
-
Fork the project repository: click on the Fork button near the top of the page. This creates a copy of the code under your account on GitHub.
-
Clone this copy to your local disk:
git clone git@github.com:YourLogin/ultimate-notion.git cd ultimate-notion -
Make sure hatch and pre-commit are installed using pipx:
pipx install hatch pipx install pre-commit -
Optionally run
hatch config set dirs.env.virtual .direnvto let VS Code find your virtual environments. If you are using VS Code, then it's quite convenient to add a file.vscode/.envin your checkout with:These settings will also be respected by pytest using pytest-dotenv.NOTION_TOKEN=TOKEN_TO_YOUR_TEST_NOTION_ACCOUNT ULTIMATE_NOTION_CONFIG=/path/to/repo/.ultimate-notion/config.toml
Set up the unit tests¶
Ultimate Notion deals with unit tests in two ways. Most tests are recorded as cassettes using VCR.py, which captures the HTTP interactions a test makes the first time it runs against the Notion API and replays them on subsequent runs. This lets the suite run offline and much faster, with no Notion account needed:
hatch run vcr-only
You only need your own Notion workspace and integration token if you want to run the tests live against the Notion API, or to add a new test or re-record an existing cassette:
hatch run vcr-rewrite # re-record all cassettes
hatch run test -k NEW_TEST # run/record a specific test live
Running tests live requires a configured test workspace, described next.
Set up a Notion test workspace¶
You only need this section to run the tests live or to re-record cassettes.
-
Create an internal integration. Open My integrations and click New integration. Choose Internal, associate it with the workspace you want to use for testing, and give it a name.
-
Enable the required capabilities. On the integration's Capabilities tab enable:
- Read, Update and Insert content, because the tests create, modify and delete pages and databases.
-
A Read user information option (with or without email addresses is fine). This is required: several tests call
Session.all_users(), which Notion rejects with403 "Personal access tokens cannot list users."for tokens that lack this capability. For the same reason you must use an internal integration token, not a personal access token. The latter can never list users. -
Copy the token. From the integration's Configuration page copy the Internal Integration Secret. It looks like
ntn_…. -
Create and share a root page. In your test workspace create a page that acts as the parent for all test content, then connect your integration to it via the page's ••• menu → Connections. Sharing the parent grants the integration access to everything created beneath it. By default the suite looks for a page titled
Tests; set theUNO_TEST_ROOT_PAGEenvironment variable to point it at a page with a different title. -
Point the configuration at the token. Set
NOTION_TOKENto the secret from step 3 (see the.vscode/.envexample above); the Ultimate Notion config resolves the token from this environment variable by default. -
Bootstrap the API-creatable objects. Run:
UNO_TEST_ROOT_PAGE='My Test Root' hatch run bootstrap-test-workspace
The command is idempotent and leaves existing objects unchanged.
Note
Three objects (All Properties DB, Wiki DB and the Custom Emoji Page) use features the API cannot create and must be built by hand. A fourth, Formula DB, is created by the script but its formula columns must be recreated in the UI, because Notion cannot filter on formula properties created via the API (issue #297); the script reports this. See tests/TEST_WORKSPACE.md for exact instructions.
Add a new live (VCR) test¶
The committed cassettes are one coherent recording of a single workspace, so you cannot simply vcr-rewrite a new test against your own workspace and commit the result: vcr-rewrite replays the shared fixture cassettes in tests/cassettes/fixtures/ (the Tests root page, the seeded databases, …) with your workspace's ids, which then diverge from the rest of the suite. Record a new test like this instead:
# 1. Bootstrap your workspace (root page named `Tests`, or set UNO_TEST_ROOT_PAGE).
# 2. Delete the shared fixture cassettes so they record fresh against your workspace
# (vcr-rewrite otherwise downgrades them to `new_episodes` and replays committed ids).
rm tests/cassettes/fixtures/mod_*.yaml
# 3. Record only your new test.
NOTION_TOKEN=ntn_… hatch run vcr-rewrite -k your_new_test
# 4. Keep ONLY your new test's cassette; restore the shared fixtures unchanged.
git checkout -- tests/cassettes/fixtures
# 5. Verify it replays offline against the committed fixtures.
hatch run vcr-only -k your_new_test
This works because cassettes are matched by request path and (for POST /v1/search) by request body, and because the ids of the shared workspace objects are normalised to stable placeholders when cassettes are written. The root page, the seeded static pages/databases, the integration bot, the workspace members and the workspace itself are recognised during recording and every occurrence of their ids — in request paths/bodies and in response bodies — is rewritten to a fixed placeholder (see the shared-id normalisation in tests/conftest.py). The same normalisation is applied when matching, so a test that asserts identity against a shared fixture (e.g. page.parent == root_page) or puts a shared object's id in a request path (e.g. GET /v1/blocks/{root_id}/children) replays against the committed fixtures even though it was recorded against your workspace's ids. Content you create under root_page keeps its own (non-shared) ids, which are internally consistent within the recording and so replay cleanly.
To support recording against a root page that cannot be named Tests, the non-default title configured via UNO_TEST_ROOT_PAGE is also scrubbed back to Tests when cassettes are written. Property, option and block ids inside the manually created databases are workspace-specific and are not normalised, so a brand-new test that asserts on those (e.g. a formula's internal property reference) may still need a hand edit.
Implement your changes¶
-
Create a branch to hold your changes:
and start making changes. Never work on the main branch!git switch -c my-feature -
Start your work on this branch. Don't forget to add docstrings in Google style to new functions, modules and classes, especially if they are part of public APIs.
-
Check that your changes don't break any unit tests with
hatch run vcr-onlyfor tests that do not generate calls to the Notion API orhatch run testfor new tests generating API calls. -
Run
hatch run lint:allandhatch run lint:fixto check the code with ruff & mypy and automatically fix ruff issues if possible. -
Add yourself to the list of contributors in
AUTHORS.md. -
When you’re done editing, do:
to record your changes in git.\ Please make sure you see the validation messages from pre-commit and fix any remaining issues.git add <MODIFIED FILES> git commit
Info
Don't forget to add unit tests and documentation in case your contribution adds a feature and is not just a bugfix.
Moreover, writing a [descriptive commit message] is highly recommended. In case of doubt, you can check the commit history with:
git log --graph --decorate --pretty=oneline --abbrev-commit --all
Submit your contribution¶
-
If everything works fine, push your local branch to the remote server with:
git push -u origin my-feature -
Go to the GitHub page of your fork and click "Create pull request" to send your changes for review.
Find more detailed information in creating a PR. You might also want to open the PR as a draft first and mark it as ready for review after the feedbacks from the continuous integration (CI) system or any required fixes.
-
Even though, these resources focus on open source projects and communities, the general ideas behind collaborating with other developers to collectively create software are general and can be applied to all sorts of environments, including private companies and proprietary code bases. ↩