# Can I store custom metadata in a note type?

**URL:** <https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303>\
**Category:** Development\
**Created:** [December 17, 2024, 3:01pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303 "2024-12-17T15:01:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![azymohliad](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@azymohliad](https://forums.ankiweb.net/u/azymohliad)\
**Post date:** [December 17, 2024, 3:01pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/1 "2024-12-17T15:01:43Z")

</div>

Hello! I’m developing [Sonaveeb Integration addon](https://ankiweb.net/shared/info/1005526508) which allows you to generate Anki notes for Estonian words. The addon creates its own dedicated note type. It can also update it automatically if the upstream version changes.

Currently I’m working on allowing the user to create their own note types with custom card templates. I can distinguish if the note type is _valid_ for the addon by checking if it has all the necessary fields. But I also want to support updating fields for the user note types, when outdated. So I also need to distinguish if the note type is _intended_ for the addon, which it might be even if not valid.

For now I require the intended note type names to start with a predefined prefix (“Sõnaveeb”), but it’s not intuitive, and may also let false positives in (the user might want to have a note type named “Sõnaveeb Something” that is not related to my addon). Ideally I would want to plant some custom flag in the default addon’s note type when I create it programmatically, so that when user clones it the flag would be inherited. Is something like this possible? Alternatively, is it possible to check whether one note type was originally cloned from another, even after they were modified?

---

<div class="post-metadata">

**Author:** ![jhhr](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jhhr/32/21339_2.png) [@jhhr](https://forums.ankiweb.net/u/jhhr)\
**Post date:** [December 17, 2024, 8:28pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/2 "2024-12-17T20:28:58Z")

</div>

There isn’t anything suitable in the available database fields, I think: [Database Structure · ankidroid/Anki-Android Wiki · GitHub](https://github.com/ankidroid/Anki-Android/wiki/Database-Structure)

A hack will have to suffice. My suggestion would be to add one extra field named something like `__metadata_dont_delete_Sõnaveeb_v1.0.5`.

- Make the field name as long as you want and include whatever info you need.
- Being a field, it’ll be included as-is when cloning the note type
- You can make your addon update the field name as needed
- Just changing a field name doesn’t require a full collection upload, unlike adding or removing a field would
- It isn’t perfect as a user might still delete it despite warnings included in the name but it ought to do the job

---

<div class="post-metadata">

**Author:** ![azymohliad](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@azymohliad](https://forums.ankiweb.net/u/azymohliad)\
**Post date:** [December 18, 2024, 8:46am UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/3 "2024-12-18T08:46:22Z")

</div>

Thanks a lot for the answer! I considered adding a “marker” field, but now I have a lot more confidence knowing this is a recommended solution. Looking at the database structure, do I understand correctly that the size overhead of an empty field is just one separator byte (0x1f) per note?

---

<div class="post-metadata">

**Author:** ![jhhr](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jhhr/32/21339_2.png) [@jhhr](https://forums.ankiweb.net/u/jhhr)\
**Post date:** [December 19, 2024, 1:49pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/4 "2024-12-19T13:49:07Z")

</div>

> do I understand correctly that the size overhead of an empty field is just one separator byte (0x1f) per note?

I hadn’t even considered how much extra data using a marker field would add to each note, but yeah that seems right according to the db details.

I didn’t realize until now but that seems to be the reason adding/removing/repositioning a field requires a full upload: every note for the note type needs to have those separators added/removed or the order of the values changed.

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [December 24, 2024, 5:04am UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/5 "2024-12-24T05:04:12Z")

</div>

Arbitrary keyed values can be stored in a notetype, and doing so is going to be more efficient than adding an unused field. Just please avoid storing large amounts of data, as that will slow Anki down.

```auto
notetype_dict["foo"] = "bar"

```

---

<div class="post-metadata">

**Author:** ![jhhr](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jhhr/32/21339_2.png) [@jhhr](https://forums.ankiweb.net/u/jhhr)\
**Post date:** [December 24, 2024, 8:02pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/6 "2024-12-24T20:02:27Z")

</div>

> [@dae](#):
>
> Arbitrary keyed values can be stored in a notetype,

Oh, nice. Are those included in an exported .apkg?

---

<div class="post-metadata">

**Author:** ![azymohliad](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@azymohliad](https://forums.ankiweb.net/u/azymohliad)\
**Post date:** [December 25, 2024, 4:52pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/7 "2024-12-25T16:52:18Z")

</div>

Oh, awesome! I haven’t released the update yet, so can still change to this easily. Will try it out and mark it as a solution if everything works. Thank you!

---

<div class="post-metadata">

**Author:** ![azymohliad](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@azymohliad](https://forums.ankiweb.net/u/azymohliad)\
**Post date:** [December 25, 2024, 5:24pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/8 "2024-12-25T17:24:09Z")

</div>

> [@jhhr](#):
>
> Are those included in an exported .apkg?

Seems to be included. I’ve exported my collection, then removed all my note types, then imported it back. The restored note type shows up in my addon, filtered by a custom key.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [January 24, 2025, 5:24pm UTC](https://forums.ankiweb.net/t/can-i-store-custom-metadata-in-a-note-type/53303/9 "2025-01-24T17:24:35Z")

</div>

Closed on January 24, 2025, 5:24pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
