Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request type hints #259

Open
lucafaggianelli opened this issue Mar 5, 2025 · 3 comments
Open

Request type hints #259

lucafaggianelli opened this issue Mar 5, 2025 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@lucafaggianelli
Copy link

Hey thanks for the amazing library!

I'm using notion sdk to create and modify pages and I find hard to write properties in the right format as explained in Notion API docs https://developers.notion.com/reference/page-property-values this is my snippet of code:

await notion.pages.create(
        parent={
            "type": "database_id",
            "database_id": "my_id",
        },
        properties={
            "Name": {
                "id": "title",
                "title": [{"type": "text", "text": {"content": data.name}}],
            },
            "Email": {"email": data.email or None},
            "Phone": {"phone_number": data.phone or None},
            "Years of Experience": {
                "number": data.years_of_experience,
            },
            "City": {
                "rich_text": [{"type": "text", "text": {"content": data.city or None}}],
            },
            "Notes": {
                "rich_text": [
                    {"type": "text", "text": {"content": data.notes or None}}
                ],
            },
        },
    )

It would be nice to have some helpers like EmailValue("luca@example.com") that creates the right dict for you {"email": "luca@example.com"} and eventually when reading a page it would include also "type": "email"

What do you think? Happy to come up with a PR

Luca

@ramnes
Copy link
Owner

ramnes commented Mar 10, 2025

Hey, thanks for the kind words. :)

I understand the appeal but I don't think a custom "language" (i.e. custom objects implemented in this library and only there) would be easier to understand and use than Notion's one. Happy to change my mind though, feel free to share your arguments.

Did you have a look at libraries that build on top of notion-sdk-py, such as notion-objects?

@ramnes ramnes added enhancement New feature or request investigate Not sure what label to add yet :) labels Mar 10, 2025
@lucafaggianelli
Copy link
Author

Hey indeed what I meant is what notion object is doing, I'll try it. Personally I don't need the full object mapping, I'd just use the Text objects and similar.

Btw I get you don't want to make the library heavier adding those objects, though I think that it would give better static type checking to the library, instead of incurring to runtime errors. Personally I spent some time to figure out the rich text format. An alternative to using objects as notion objects is doing, could be using TypedDict to have typechecking and autocomplete in the IDE.

@ramnes
Copy link
Owner

ramnes commented Mar 10, 2025

Fair enough. Just like I already agreed that we could have type hints for the responses if someone is willing to add them and maintain them (c.f. #199, #242), it probably makes sense that I also agree on type hints for the requests. :)

I’m still unsure about the shape it should take, but so far I’m mostly leaning toward using typed dicts.

@ramnes ramnes changed the title Add Page properties helpers Request type hints Mar 10, 2025
@ramnes ramnes added help wanted Extra attention is needed and removed investigate Not sure what label to add yet :) labels Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants