Manage Object Storage in Python
Learn how to use the Python Object Storage client library to manage objects from your Replit App.
This guide demonstrates how to use the Python client library to upload, list, download, and delete objects in your Object Storage bucket.
Create a Python Replit App
- Select
Create App from the home screen.
- Navigate to the Choose a Template tab.
- Type “Python” in the template search field and select it as shown below:
- Select
Create App.
Install the official client library
To install the client library, follow the one-click setup or package manager instructions below.
Access the Object Storage tool
- Navigate to the Object Storage tab.
- Select the
Commands view in the Object Storage tab.
The installation screen should resemble the following screenshot:
Install the dependencies
- Select “Python” from the programming language dropdown on the top left.
- Select Install replit-object-storage package.
- When completed, the button text should read Package installed.
Access the Object Storage tool
- Navigate to the Object Storage tab.
- Select the
Commands view in the Object Storage tab.
The installation screen should resemble the following screenshot:
Install the dependencies
- Select “Python” from the programming language dropdown on the top left.
- Select Install replit-object-storage package.
- When completed, the button text should read Package installed.
Use this option if your Replit App uses the Universal Package Manager (upm
) to manage its dependencies.
Open the Shell tool in your workspace and enter the following command:
Use this option if your Replit App uses pip
to manage its dependencies.
Open the Shell tool in your workspace and enter the following command:
Create a bucket
Before storing objects, you must create a bucket. Follow the steps below to create a new bucket:
- Navigate to the Object Storage tool
- Select Create new bucket
- Enter a name for the bucket in the Name field
- Select Create bucket
Add and run the example code
Locate main.py
Open the Files tool from the left dock.
Select main.py
to open it in a file editor.
Add the client code
Copy and paste the following code into main.py
:
Run the app
Select Run to execute the example code.
Navigate to the Console tab to view the output, which should resemble the output below:
Confirm that the file.txt
object appears in your bucket in the Objects view of the
Object Storage tool.
Reload the page to update the object list if file.txt
fails to appear.
Delete the object
To remove the file.txt
file from the bucket,
-
Replace the content of
main.py
with the following code: -
Select Run to execute the example code.
-
Navigate to the Console tab to view the output, which should resemble the output below:
-
Verify that the
file.txt
object no longer appears in the bucket.
Next steps
To learn more about Replit Object Storage, see the following resources:
- Object Storage: Learn more about the Object Storage feature and workspace tool
- Object Storage Python SDK: Learn about the
Client
class and its methods