Import as .txt with specified card model

Hi there,

Roughly a year ago I started trying to reverse-engineer the Anki database schema (with the help of the documentation provided by the AnkiDroid repository on GitHub). While my approach was successful it was not really resilient. I know it is not possible to have apps or websites connect to the Anki mobile app like AnkiDroid on android. My question thus is: what is the easiest way to import a bunch of cards together with a specific model or at least kinda referenced to one so that when reviewing cards after importing them they show up in the proper form and in the right deck. I read importing plain text files works pretty good for basic use cases, but I wonder if there’s an easier and better way to achieve what I want while retaining meta data about the cards model.

Thanks!

2 Likes

You can specify the notetype and field mapping, but it’s not possible to define the notetype inside the file, so if you’re distributing things to others, you’d need to get them to import an .apkg with the notetype first.

https://docs.ankiweb.net/importing/text-files.html#file-headers

3 Likes

Thanks for the swift reply Damian. From a practical point of view: Would the most feasible option be, to simply create an empty deck where the note type is defined and after this one is imported once then users could simply continue importing CSVs?

I am asking as I had some trouble getting all the fields of the SQLite database right the last time I worked on the project; Mainly the ordering was messed up (You answered this already on a separate occasion if I am not mistaken). Simply importing CSVs seems to be the better option here.

I don’t think you can do it with an “empty” deck – but you can create a single sample note that will carry all the parameters of the notetype with it when you export it as an APKG.

The bonus is that you can export that sample note as a CSV as well, and that will give you the columns/fields structure you’ll need to enter your data correctly.

It’s possible I’m not understanding your use-case, but if this is something you’re going to share with other users, it seems easier to export it as a unified APKG, than to export it as a sample-note APKG followed by CSVs with all the data.

3 Likes

My way of thinking is the following: To gather the necessary information about the used model an import of an .apkg file is necessary only once. All subsequent imports could then be done via .csv which is simply easier to deal with than a SQLite db. As stated above, my main motivation stems from the fact that I went down the route to offer importing .apkg files before, but kinda ran into problems here with the card ordering (probably due to some misconfigured values in the ‘due’ column. Thus instead of doing the difficult work here myself I’d simply import a .csv and let Anki figure out the rest internally (I expect the due date of these new cards to be set in the order they appear in said .csv). I hope my reasoning is clearer now.

If you’re trying to create your import file manually – yes, of course a CSV is easier than a database/APKG.

But if you’re creating your import file by export from Anki – a database/APKG is easier/more fully featured than a CSV.

1 Like

Yeah of course. If I’d create the data through Anki’s own export function it would be silly not to choose exporting an .apkg file. But I am rather getting the data elsewhere and simply wish for an easy way to import these collections into Anki.

That’s why I thought I must not be understanding your use case correctly. Cheers.

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