seems like I found a way to open apkg file and remove not needed cards(or notes in my case, not sure if it is a correct way):
from anki.collection import ImportAnkiPackageRequest, Collection
collection = Collection("collection.anki2")
collection.import_anki_package(
ImportAnkiPackageRequest(
package_path="4000.apkg"
)
)
for c in collection.find_notes(""):
note = collection.get_note(c)
word = note.fields[0]
# print(note.card_ids)
# print(word)
if word != "arch":
collection.remove_notes([note.id])
but now how to save this collection as apkg deck please?