Registry / auth-security / iab-tcf

iab-tcf

JSON →
library0.2.2pypypi✓ verified 79d ago

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.

pip install iab-tcf
INSTALL
IMPORT
SIG · IAB-TCF
I
iab-tcf
auth-securitypythonv0.2.2
Install
1.9s avg
Import
Disk
19MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 1.9s
py 3.11
✕ build_error
✕ build_error
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 1.9s
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ConsentV2
from iab_tcf import ConsentV2
from iab_tcf import TCString
ConsentV1
from iab_tcf import ConsentV1
Reader
from iab_tcf import Reader

Decode a v2 string and encode a v1 string.

from iab_tcf import TCString, ConsentString # Decode a v2 consent string tc_string = "CPzA4hAPzA4hAAGABBENAtEgAAAAAAAAAAYgAAAAAA" tc = TCString(tc_string) print("Vendor consents:", tc.vendor_consents) # Encode a v1 consent string from datetime import datetime cs = ConsentString() cs.set_version(1) cs.set_created(datetime.now()) cs.set_last_updated(datetime.now()) cs.set_cmp_id(1) cs.set_cmp_version(1) cs.set_consent_screen(1) cs.set_consent_language("EN") cs.set_vendor_list_version(1) cs.set_tcf_policy_version(1) cs.set_purpose_allowed([1,2]) cs.set_vendors_allowed([1,2]) encoded = cs.encode() print("Encoded v1 string:", encoded)
Debug
Known issues
gotchaThe library uses 'vendor_consents' property for v2, but 'get_vendors_allowed' for v1. Mixing them causes AttributeError.
fix
Check version: v2 strings use properties like .vendor_consents and .purpose_consents; v1 uses methods like .get_vendors_allowed().
affects: all
gotchaEncoding a v1 string requires setting many fields manually; skipping required fields leads to incomplete or invalid strings.
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.
affects: all
gotchaThe bitarray-hardbyte dependency is not a typo; it's a fork of bitarray. Installing without it or using standard bitarray will fail.
fix
Ensure bitarray-hardbyte is installed, not bitarray. pip install iab-tcf handles this automatically.
affects: all
deprecatedv1.1 support is deprecated in the IAB standard; the library still supports it but it's recommended to use v2 only.
fix
Use TCString for v2 strings instead of ConsentString when possible.
affects: all
Upgrade
Version history
0.2.2latest on PyPI · released Oct 31, 2022
Audit
Dependencies
bitarray-hardbyterequiredBit manipulation for consent strings
Agent activity
23 hits · last 30 days
node
22
OpenAI (training)
1
Resources