Skip to main content

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

"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)

Metadata

Release files for py-anki 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-anki 0.0.6
File Size Uploaded
py_anki-0.0.6.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-anki 0.0.6
File Interpreter ABI Platform
py_anki-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / py_anki-0.0.6.tar.gz

Download URL py_anki-0.0.6.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
376350d3175392275b6ef78880c3b8ea12af85b1fe952987ee6e90a4e9784600
BLAKE2b-256 checksum
How to use checksums
a305ab745586a1a03a496311bb19d9bed6ebd1b558d871680aa8abd9d7a8534e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / py_anki-0.0.6-py3-none-any.whl

Download URL py_anki-0.0.6-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d711f89725d6b508cb19515624106e9f11c1633563fd09a0117863905e560c2
BLAKE2b-256 checksum
How to use checksums
01d7699930f291f8782059c0b6dc1adf66ae98741f0a8a99a4cb9146a6d31939
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page