{"id":24392,"library":"pyscard","title":"pyscard - Smartcard module for Python","description":"pyscard is a Python library for smart card communication using PC/SC API. It provides high-level wrappers for reading/writing to smart cards, monitoring card insertion/removal, and sending APDUs. Version 2.3.1 (October 2025) supports Python >=3.9 and SWIG 4.4. Active development with monthly releases.","status":"active","version":"2.3.1","language":"python","source_language":"en","source_url":"https://github.com/LudovicRousseau/pyscard","tags":["smartcard","pcsc","smart-card","security","hardware"],"install":[{"cmd":"pip install pyscard","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Requires PC/SC service (pcscd on Linux, winscard on Windows, SmartCardServices on macOS)","package":"pyscard","optional":false}],"imports":[{"note":"CardRequest is in a submodule, not directly in smartcard","wrong":"from smartcard import CardRequest","symbol":"CardRequest","correct":"from smartcard.CardRequest import CardRequest"},{"note":"CardConnection is a class, not a module","wrong":"import smartcard.CardConnection","symbol":"CardConnection","correct":"from smartcard.CardConnection import CardConnection"},{"note":"SCard* functions are in scard submodule","wrong":"from smartcard import SCardGetErrorMessage","symbol":"SCardGetErrorMessage","correct":"from smartcard.scard import SCardGetErrorMessage"}],"quickstart":{"code":"import smartcard.util\nfrom smartcard.CardRequest import CardRequest\nfrom smartcard.CardConnection import CardConnection\n\ndef get_atr():\n    request = CardRequest(timeout=5)\n    card_service = request.waitforcard()\n    card_service.connection.connect()\n    atr = card_service.connection.getATR()\n    print('ATR:', smartcard.util.toHexString(atr))\n    card_service.connection.disconnect()\n\nif __name__ == '__main__':\n    get_atr()","lang":"python","description":"Wait up to 5 seconds for a smart card, connect, retrieve and print the ATR."},"warnings":[{"fix":"Install and start pcscd: sudo apt install pcscd && sudo systemctl enable --now pcscd","message":"pyscard requires PC/SC service running. On Linux, ensure pcscd is installed and started (e.g., sudo systemctl start pcscd).","severity":"gotcha","affected_versions":"all"},{"fix":"Use from smartcard.scard import SCardEstablishContext only if necessary; prefer CardRequest","message":"Direct import of smartcard.scard functions like SCardEstablishContext is discouraged; use higher-level classes CardRequest and CardConnection.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Update code to not manually allocate buffers; let pyscard handle memory.","message":"In 2.3.0, SCardListReaders() and SCardListReaderGroups() were fixed to use SCARD_AUTOALLOCATE. Code relying on manual memory management may break.","severity":"breaking","affected_versions":"2.3.0+"},{"fix":"Create a new CardConnection or CardRequest after release.","message":"In 2.3.0, connecting after releasing a connection raises an exception. Code that reuses a released connection will break.","severity":"breaking","affected_versions":"2.3.0+"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"pip install pyscard","cause":"pyscard not installed.","error":"ModuleNotFoundError: No module named 'smartcard'"},{"fix":"Start pcscd on Linux, ensure reader is plugged in, and check reader drivers on Windows/macOS.","cause":"PC/SC service not running or no reader connected.","error":"smartcard.scard.SCardException: Cannot connect to smart card reader (0x80100001)"},{"fix":"Install libpcsclite1 on Debian/Ubuntu: sudo apt install libpcsclite1","cause":"Missing PC/SC runtime library.","error":"ImportError: libpcsc.so.1: cannot open shared object file: No such file or directory"},{"fix":"Use from smartcard.CardRequest import CardRequest","cause":"Incorrect import path.","error":"AttributeError: module 'smartcard' has no attribute 'CardRequest'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}