Install & Compatibility
Where this runs
tested against v2.16.0.dev2024021410 · 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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 33.6MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 34.5s · import 8.806s · 2252.8MB
921MB installed
● package 921MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
keras
✓ from tensorflow import keras
keras
✓ import tensorflow.keras as keras
✗ import keras
While 'keras' (the multi-backend Keras 3 package) and 'tf.keras' often expose the same API, 'tf-keras-nightly' specifically refers to the Keras implementation bundled with TensorFlow. Directly importing 'keras' might point to a different Keras installation or an older Keras 2 if not explicitly managed.
This quickstart demonstrates how to define, compile, train, and save a basic Keras Sequential model using the `tensorflow.keras` API. It uses dummy data for a simple classification task.
import tensorflow as tf
import os
# Ensure Keras backend is set to TensorFlow if running multi-backend Keras 3
# (though tf-keras-nightly implies TensorFlow backend by nature)
# os.environ["KERAS_BACKEND"] = "tensorflow"
# Import Keras from TensorFlow's namespace
from tensorflow import keras
from keras import layers
# Define a simple sequential model
model = keras.Sequential([
layers.Dense(64, activation='relu', input_shape=(784,)),
layers.Dense(64, activation='relu'),
layers.Dense(10, activation='softmax')
])
# Compile the model
model.compile(
optimizer=keras.optimizers.Adam(learning_rate=0.001),
loss=keras.losses.SparseCategoricalCrossentropy(),
metrics=[keras.metrics.SparseCategoricalAccuracy()]
)
# Generate dummy data
import numpy as np
x_train = np.random.rand(100, 784).astype('float32')
y_train = np.random.randint(0, 10, 100).astype('int32')
# Train the model
print("Starting model training...")
model.fit(x_train, y_train, epochs=1, batch_size=32)
print("Model training finished.")
# Save the model (using the recommended .keras format)
model.save('my_model.keras')
print("Model saved as my_model.keras")
# Load the model
loaded_model = keras.models.load_model('my_model.keras')
print("Model loaded successfully.")
Debug
Known issues
breakingKeras optimizers were moved to `tf.keras.optimizers.legacy` starting with TensorFlow 2.12. Directly instantiating `keras.optimizers.Adam()` (or other optimizers) will use the new Keras 3 optimizers, which handle state differently and may break checkpoint loading from models trained with older optimizers.fixIf encountering checkpoint loading issues or needing to use the old optimizer behavior, explicitly use the legacy optimizers: `tf.keras.optimizers.legacy.Adam()`.
affects: TensorFlow 2.12+ (and corresponding tf-keras-nightly versions)
breakingThe default Keras model saving format for `model.save()` is now the `.keras` format (Keras V3 format), not the legacy H5 format, when using `model.save('my_model.keras')`. This change was introduced with TensorFlow 2.13 and Keras 2.13.fixTo save in the legacy H5 format, explicitly specify `save_format="h5"`: `model.save('my_model.h5', save_format="h5")`. affects: TensorFlow 2.13+ (and corresponding tf-keras-nightly versions)
gotcha`tf-keras-nightly` is a nightly build, meaning it's built from the latest development branch and is not guaranteed to be stable or backward compatible between daily releases.fixUse `tf-keras-nightly` for access to the newest features and bug fixes, but be prepared for potential instability or API changes without notice. For production environments, prefer stable releases of `tensorflow`.
affects: All versions
gotchaRequires Python >=3.10. Installing with older Python versions will result in an installation error.fixEnsure your Python environment is version 3.10 or newer before installing `tf-keras-nightly`.
affects: All versions
breaking`tensorflow` module not found. This typically means the the `tensorflow` package has not been installed in the current Python environment.fixEnsure `tensorflow` is installed by running `pip install tensorflow` in your environment.
affects: All versions
Upgrade
Version history
2.21.0.dev2026082609latest on PyPI · released Aug 26, 2026
Audit
Dependencies
tensorflow-nightlyoptionaltf-keras-nightly is the Keras API integrated within TensorFlow, typically used with the corresponding TensorFlow nightly build for the latest features and compatibility.