{"id":21449,"library":"iab-tcf","title":"IAB TCF","description":"A Python implementation of the IAB Transparency and Consent Framework (TCF) consent strings, supporting both v1.1 and v2. Current version: 0.2.2, with Python 3.6+ support. Low release cadence.","status":"active","version":"0.2.2","language":"python","source_language":"en","source_url":"https://github.com/gguridi/iab-tcf","tags":["iab","tcf","consent","gdpr","privacy","tcstring"],"install":[{"cmd":"pip install iab-tcf","lang":"bash","label":"pip"}],"dependencies":[{"reason":"Bit manipulation for consent strings","package":"bitarray-hardbyte","optional":false}],"imports":[{"note":"TCString is exposed at top level","wrong":"from iab_tcf.tcstring import TCString","symbol":"TCString","correct":"from iab_tcf import TCString"},{"note":"ConsentString is also top level","wrong":"from iab_tcf.consent import ConsentString","symbol":"ConsentString","correct":"from iab_tcf import ConsentString"}],"quickstart":{"code":"from iab_tcf import TCString, ConsentString\n\n# Decode a v2 consent string\ntc_string = \"CPzA4hAPzA4hAAGABBENAtEgAAAAAAAAAAYgAAAAAA\"\ntc = TCString(tc_string)\nprint(\"Vendor consents:\", tc.vendor_consents)\n# Encode a v1 consent string\nfrom datetime import datetime\ncs = ConsentString()\ncs.set_version(1)\ncs.set_created(datetime.now())\ncs.set_last_updated(datetime.now())\ncs.set_cmp_id(1)\ncs.set_cmp_version(1)\ncs.set_consent_screen(1)\ncs.set_consent_language(\"EN\")\ncs.set_vendor_list_version(1)\ncs.set_tcf_policy_version(1)\ncs.set_purpose_allowed([1,2])\ncs.set_vendors_allowed([1,2])\nencoded = cs.encode()\nprint(\"Encoded v1 string:\", encoded)","lang":"python","description":"Decode a v2 string and encode a v1 string."},"warnings":[{"fix":"Check version: v2 strings use properties like .vendor_consents and .purpose_consents; v1 uses methods like .get_vendors_allowed().","message":"The library uses 'vendor_consents' property for v2, but 'get_vendors_allowed' for v1. Mixing them causes AttributeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Always set version, created, last_updated, cmp_id, cmp_version, consent_screen, consent_language, vendor_list_version, tcf_policy_version, purpose_allowed, and vendors_allowed.","message":"Encoding a v1 string requires setting many fields manually; skipping required fields leads to incomplete or invalid strings.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure bitarray-hardbyte is installed, not bitarray. pip install iab-tcf handles this automatically.","message":"The bitarray-hardbyte dependency is not a typo; it's a fork of bitarray. Installing without it or using standard bitarray will fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Use TCString for v2 strings instead of ConsentString when possible.","message":"v1.1 support is deprecated in the IAB standard; the library still supports it but it's recommended to use v2 only.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use .vendor_consents property instead of .get_vendors_allowed() for v2 strings.","cause":"Using v1 method on v2 TCString object.","error":"AttributeError: 'TCString' object has no attribute 'get_vendors_allowed'"},{"fix":"Run 'pip install iab-tcf' which will install bitarray-hardbyte automatically. If manually installing, use 'pip install bitarray-hardbyte'.","cause":"The dependency 'bitarray-hardbyte' is missing or not installed correctly.","error":"ModuleNotFoundError: No module named 'bitarray'"},{"fix":"Ensure the consent string is a valid base64-encoded IAB string. Example: 'CPzA4hAPzA4hAAGABBENAtEgAAAAAAAAAAYgAAAAAA'.","cause":"Passing an empty or malformed consent string to TCString.","error":"ValueError: invalid literal for int() with base 10: ''"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}