Registry / ai-ml / tflite

tflite

JSON →
library2.18.0pypypi✓ verified 81d ago

A pure Python parser for TensorFlow Lite models (*.tflite) that extracts model metadata, operator codes, subgraphs, and tensors without requiring TensorFlow runtime. Current version 2.18.0 corresponds to TensorFlow 2.18.0 schema. Releases follow TensorFlow's major.minor versions, with occasional patches.

pip install tflite
INSTALL
IMPORT
SIG · TFLITE
T
tflite
ai-mlpythonv2.18.0
Install
3.9s avg
Import
418ms
Disk
91MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.18.0 · 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
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.404s · 91.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.9s · import 0.432s · 88MB
91MB installed
● package 91MB
Code
Verified usage

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

Model
from tflite import Model
import tflite

Parses a TFLite file and prints each operator's name.

import tflite # Load a TFLite model file (must be a .tflite file) with open('/path/to/model.tflite', 'rb') as f: buf = f.read() # Parse the model model = tflite.Model.GetRootAsModel(buf, 0) # Access version print('Model version:', model.Version()) # Access operator codes for i in range(model.OperatorCodesLength()): opcode = model.OperatorCodes(i) code = opcode.BuiltinCode() print('Opcode', i, ':', tflite.BUILTIN_OPCODE2NAME.get(code, 'UNKNOWN'))
Debug
Known issues
gotchaThe package version must match the TensorFlow version that generated the model. Using tflite 2.10.0 to parse a model from TF 2.18.0 may fail due to schema changes (e.g., new operator codes).
fix
Align tflite version with the TensorFlow version used to create the model.
affects: all
gotchaThe model buffer must be read as bytes (binary mode). Passing a text string or reading as text will lead to parsing errors.
fix
Use 'rb' mode: open(path, 'rb').read()
affects: all
deprecatedOperatorCode.BuiltinCode() may be deprecated in future releases; check the README for compatibility handling. In TF 2.4.0+, the method exists but the schema may expose 'builtin_code' directly on the operator code object.
fix
Use tflite.OperatorCode.BuiltinCode() as documented, but watch for direct attribute access in newer flatbuffers.
affects: >=2.4.0
gotchaThe package does not validate that the input file is a valid TFLite model. If the buffer is malformed, the GetRootAsModel call may succeed but subsequent accesses can raise exceptions.
fix
Wrap usage in try/except blocks when dealing with untrusted files.
affects: all
Upgrade
Version history
2.18.0latest on PyPI · released Jan 28, 2025
Audit
Dependencies
flatbuffersrequiredRequired for deserializing TFLite FlatBuffer files
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
tflite — pip install tflite · libregistry