Replit Python Library

raw JSON →
4.1.2 verified Sat May 09 auth: no python

A library for interacting with Replit features such as the Replit Database (key-value store), Identity (auth tokens), Audio (deprecated), and other platform utilities. Current version 4.1.2 requires Python >=3.10, <4.0. Release cadence is irregular.

pip install replit
error ModuleNotFoundError: No module named 'replit.audio'
cause Audio module was removed in v4.0.0.
fix
Replace from replit.audio import Audio with something else or update your code to not use Audio.
error AttributeError: module 'replit' has no attribute 'Database'
cause You might be using an older version (<3.0) where Database was in a submodule.
fix
Upgrade to latest version: pip install --upgrade replit and use from replit import Database.
error replit_python_flask_import_error: Flask not installed
cause The `replit.web` module depends on Flask, which is an optional dependency.
fix
Install Flask: pip install flask, or avoid using replit.web.
breaking In v4.0.0, the Audio module was removed entirely. Code using `from replit import Audio` or `from replit.audio import Audio` will break. There is no replacement provided.
fix Remove any Audio usage. If you need audio playback, use a third-party library like `playsound`.
breaking In v3.6.1, Database keys with leading slashes were forbidden. The v3.6.3 release reverted this change, but if you upgraded to 3.6.1 or 3.6.2 and saved keys with slashes, they may have been stripped. Check your keys.
fix If you used those versions and stored keys with leading slashes, you may need to re-add the slashes manually using a newer version.
deprecated The `web` module (Flask/SocketIO integration) is considered deprecated in favor of standalone Flask or Starlette apps. It may be removed in a future major version.
fix Avoid using `replit.web`. Use Flask or Starlette directly.
gotcha When using `Database` outside of Replit environment, you must manually set `REPLIT_DB_URL`. The library does not provide a fallback.
fix Set the environment variable `REPLIT_DB_URL` to a database endpoint URL (e.g., a local test server or the real Replit DB URL).
pip install replit==4.1.2

Basic usage of Replit Database (key-value store). Requires the REPLIT_DB_URL environment variable, which is automatically set in Replit environments.

import os
from replit import Database

# Get database URL from environment variable (set automatically in Replit)
db_url = os.environ.get('REPLIT_DB_URL', '')
if not db_url:
    print('REPLIT_DB_URL not set. Running outside Replit?')
else:
    db = Database(db_url)
    db['key'] = 'Hello from replit-py'
    print(db['key'])