Skip to main content

A simple API for Anki Spaced Repetition

Project description

"اعوذ بالله من الشیطان الرجیم"

"I seek refuge in Allah from shaitan, the accursed one."

"بسم الله الرحمن الرحيم"

"In the name of Allah, the Most Gracious, the Most Merciful."

"إياك نعبد و إياك نستعين"

"It is You we worship and You we ask for help."

- Al Fatihah : 05



Py-Anki



About


Py-Anki is an unofficial python binding/wrapper for AnkiConnect RESTful API. You can control all your Anki actions (eg: Create Deck, Add Notes, Get Card Info) using this package, in a more pythonic way.

Documentation

Warning : This package is under development yet.


Steps to use the API


  • First of all you need to install AnkiConnect addon on your Anki Software.
  • Then, run Anki Software and switch to your desired profile.
  • Now run the example codes mentioned below...

Examples


  • Create Deck


    # import api class from py-anki package
    from py_anki import AnkiApi
    
    # create an instance of the api class
    anki = AnkiApi()
    
    # store deck creation query
    deck = anki.create_deck('New Deck')
    
    # execute the query
    anki.exec(deck)
    

    Expected Result :



  • Create Model / Note Type


    # import api class from py-anki package
    from py_anki import AnkiApi
    
    # create an instance of the api class
    anki = AnkiApi()
    
    # store model creation query
    model = anki.create_model('New Model')
    
    # execute the query
    anki.exec(model)
    

    Expected Result :



  • Create Single Note


    # import api class from py-anki package
    from py_anki import AnkiApi
    
    # create an instance of the api class
    anki = AnkiApi()
    
    # populate note fields
    field1 = 'What is your name?' # for Front field
    field2 = 'arman_bhaai'
    note_fields = [field1,field2]
    
    # store note creation query
    note = anki.create_note(note_fields, deck_name='New Deck', model_name='New Model')
    
    # execute the query
    anki.exec(note)
    

    Expected Result :





  • Create Multiple Notes with Media


    # import api class from py-anki package
    from py_anki import AnkiApi
    
    # create an instance of the api class
    anki = AnkiApi()
    
    # store picture from the web for Note 1
    note1_picture = anki.fetch_picture(
      url='https://images.all-free-download.com/images/graphiclarge/beautiful_flower_series_04_hd_pictures_166886.jpg', 
      filename='flower_jasmin.jpg',
      fields=['Front, Back']
    )
    
    # store audio from the web for Note 1
    note1_audio1 = anki.fetch_audio(
      url='https://lex-audio.useremarkable.com/mp3/jasmine_us_1.mp3', 
      filename='pronunc_jasmine.mp3', 
      fields=['Back']
    )
    
    # store another audio from the web for Note 1
    note1_audio2 = anki.fetch_picture(
      url='https://lex-audio.useremarkable.com/mp3/flower_us_1.mp3',
      filename='pronounc_flower.mp3',
      fields=['Back']
    )
    note1 = anki.create_note(
      field_vals=['What is the name of this flower?', 'Jasmine'],
      deck_name='Default',
      model_name='Basic',
      audios=[note1_audio1, note1_audio2],
      pictures=[note1_picture],
      making_note_list=True
    )
    
    # store picture from the web for Note 2
    note2_picture = anki.fetch_picture(
      url='https://upload.wikimedia.org/wikipedia/commons/a/a6/Green_dome%2C_Masjid_e_Nabawi%2C_Medina%2C_KSA.jpg', 
      filename='masjid-e-nawawi.jpg',
      fields=['Front']
    )
    
    # store audio from the web for Note 2
    note2_audio1 = anki.fetch_audio(
      url='https://lex-audio.useremarkable.com/mp3/medina_1_us_2.mp3', 
      filename='pronunc_medina.mp3', 
      fields=['Back']
    )
    
    # store note with populated fields and media
    note2 = anki.create_note(
      field_vals=['Masjid e Nawawi is located in?', 'Medina'],
      deck_name='Default',
      model_name='Basic',
      audios=[note2_audio1],
      pictures=[note2_picture],
      making_note_list=True
    )
    
    # store list of notes
    notes = anki.create_notes([note1, note2])
    
    # execute the query
    anki.exec(notes)
    

    Expected Result :








Class Reference (More to be added later...)


### Class (* -> required)
AnkiApi(host:str, port:str)


  ### Attributes (Public)
  host:str

  port:str

  ### Methods (Public)
  create_model(*model_name:str, *in_order_model_fields:list, card_name:str, model_css:str, template_front:str, template_back:str) -> dict

  create_deck(*deck_name:str) -> dict

  fetch_picture(*url:str, *filename:str, fields:list) -> dict

  fetch_audio(*url:str, *filename:str, fields:list) -> dict

  create_note(*field_vals:list, deck_name:str, model_name:str, allow_duplicate:bool, tags:list, audios:list, making_note_list:bool) -> dict

  create_notes(*notes:list) -> dict

  exec(req_query:dict) -> json_obj

  ### Methods (Private)
  _find_model_fields_by_name(*model_name:str) -> list

  _catch_error(*json_resp:json_obj)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_anki-0.0.6.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

py_anki-0.0.6-py3-none-any.whl (10.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page