Skip to main content

Streamlit Swipecards allow you to add interactive swipeable cards to your app. Supports both image cards and table row swiping with cell highlighting.

Project description

Streamlit Swipe Cards

A modern card-swiping component for Streamlit. Build swipe interfaces using images or rows from a data table.

Features

  • Stacked card interface with smooth animations
  • Works on both touch and mouse devices
  • Like, pass and undo actions
  • Optional table view powered by AG‑Grid
  • Cell, row and column highlighting support
  • Automatic table caching for improved performance when loading the same dataset multiple times

Installation

pip install streamlit-swipecards

Quick demo

Launch the sample app to see both modes in action:

streamlit run example.py

Usage

Image cards

import streamlit as st
from streamlit_swipecards import streamlit_swipecards

cards = [
    {"name": "Alice", "description": "Loves hiking", "image": "https://.../alice.jpg"\},
    {"name": "Bob", "description": "Chef and foodie", "image": "https://.../bob.jpg"\},
]

result = streamlit_swipecards(cards=cards, display_mode="cards", key="people")
if result:
    st.json(result)

Table cards

Provide a list of card dictionaries. Each card points to the dataset and the row it should display. Highlighting and centering options are set per card.

csv_path = "sample_data.csv"

cards = [
    {
        "dataset_path": csv_path,
        "row_index": 0,
        "name": "Alice Johnson",
        "description": "Engineering professional from New York",
        "highlight_cells": [{"row": 0, "column": "Salary", "color": "#FFB6C1"}],
        "center_table_row": 0,
        "center_table_column": "Salary",
    },
    {
        "dataset_path": csv_path,
        "row_index": 1,
        "name": "Bob Smith",
        "description": "Sales professional from California",
        "highlight_cells": [{"row": 1, "column": "Rating", "color": "#98FB98"}],
        "center_table_row": 1,
        "center_table_column": "Rating",
    },
]

result = streamlit_swipecards(cards=cards, display_mode="table", key="table")
if result:
    st.json(result)

Card dictionaries

Image card

{
    "name": "Alice",       # required
    "description": "Text", # required
    "image": "URL or base64"
}

Table card

{
    "dataset_path": "data.csv",               # required
    "row_index": 0,                            # row to display
    "name": "Row title",                      # optional
    "description": "Row description",         # optional
    "highlight_cells": [{"row": 0, "column": "Salary", "color": "#FFB6C1"}],
    "highlight_rows": [{"row": 0, "color": "#E3F2FD"}],
    "highlight_columns": [{"column": "Rating", "color": "#E8F5E8"}],
    "center_table_row": 0,
    "center_table_column": "Salary"
}

API reference

streamlit_swipecards(
    cards=None,
    dataset_path=None,         # legacy single-dataset mode
    highlight_cells=None,
    highlight_rows=None,
    highlight_columns=None,
    display_mode="cards",      # "cards" or "table"
    center_table_row=None,
    center_table_column=None,
    key=None,
) 

Return value

The component returns a dictionary:

{
    "swipedCards": [{"index": 0, "action": "right"}, ...],
    "lastAction": {"cardIndex": 0, "action": "right"},
    "totalSwiped": 3,
    "remainingCards": 7
}

How to Use

  1. Swipe right 💚 or click the like button to like a card
  2. Swipe left ❌ or click the pass button to pass on a card
  3. Click back ↶ to undo your last action
  4. Cards stack behind each other for a realistic experience
  5. Smooth animations provide visual feedback

Performance

The component automatically caches loaded datasets to improve performance when multiple cards reference the same file. This means:

  • No redundant file reads: The same dataset file is only loaded once, even if multiple cards use it
  • Automatic cache invalidation: When a file is modified, the cache is automatically updated
  • Memory efficient: Uses Streamlit's built-in @st.cache_data for optimal memory management

To see the performance benefits in action, run:

python demo_caching.py

Released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_swipecards-0.2.6.tar.gz (23.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_swipecards-0.2.6-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_swipecards-0.2.6.tar.gz.

File metadata

  • Download URL: streamlit_swipecards-0.2.6.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for streamlit_swipecards-0.2.6.tar.gz
Algorithm Hash digest
SHA256 46d3ef31de98b5bf2d906cbc59cca8a54175f155a32ec179676812c4ad5ec7cf
MD5 1ee673f5868dacc49c1861b58cd55478
BLAKE2b-256 64d3708a15cd081e0175facf4d0f551790593218ee4d6920c40dceb13aa6c049

See more details on using hashes here.

File details

Details for the file streamlit_swipecards-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_swipecards-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d49fb5956ec1a8e9e114e1b757f17b7f431d0030c788769c510d0e5413c75f92
MD5 cab2398a439d44cf60d9dabfc9f3d556
BLAKE2b-256 9f4df1f16b747b7c5581a6f625bee411174c9aee7f1fcd4e9a632fde658dab88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page