跳转到主要内容

未提供项目描述

项目描述

一个纯Python,React风格的框架,用于扩展您的Jupyter和Web应用

solara logo

加入我们并在 Discord 上聊天,提出问题或分享您的想法或创作!

Discord Shield

介绍Solara

虽然现在有很多Python Web框架,但大多数都是为小型数据应用设计的,或者使用未经证实的用于更大规模的模式。随着应用的复杂性增加,代码组织、可重用性和状态往往会受到影响,从而导致代码混乱或者将任务卸载到React应用中。

Solara 解决了这一差距。使用类似React的API,我们无需担心可伸缩性。React 已经证明了其支持世界上最大的Web应用的能力。

Solara 使用React的纯Python实现(Reacton),创建基于ipywidget的应用程序。这些应用既可以在Jupyter Notebook内部使用,也可以作为使用FastAPI等框架的独立Web应用。这种模式使得基于组件的代码和极简单的状态管理变得可能。

通过在ipywidgets之上构建,我们自动利用现有的widget生态系统,并在包括JupyterLab、Jupyter Notebook、Voilà、Google Colab、DataBricks、JetBrains Datalore等多个平台上运行。

我们关心开发者体验。Solara 将为您提供热代码重新加载和类型提示,以加快开发速度。

安装

运行

pip install solara

或遵循 安装说明 获取更详细的说明。

第一个脚本

将以下Python代码片段放入一个文件中(我们建议使用 sol.py),或者将其放入Jupyter笔记本的一个单元中

import solara

# Declare reactive variables at the top level. Components using these variables
# will be re-executed when their values change.
sentence = solara.reactive("Solara makes our team more productive.")
word_limit = solara.reactive(10)


@solara.component
def Page():
    # Calculate word_count within the component to ensure re-execution when reactive variables change.
    word_count = len(sentence.value.split())

    solara.SliderInt("Word limit", value=word_limit, min=2, max=20)
    solara.InputText(label="Your sentence", value=sentence, continuous_update=True)

    # Display messages based on the current word count and word limit.
    if word_count >= int(word_limit.value):
        solara.Error(f"With {word_count} words, you passed the word limit of {word_limit.value}.")
    elif word_count >= int(0.8 * word_limit.value):
        solara.Warning(f"With {word_count} words, you are close to the word limit of {word_limit.value}.")
    else:
        solara.Success("Great short writing!")


# The following line is required only when running the code in a Jupyter notebook:
Page()

在您放置文件(sol.py)的同一目录下从命令行运行

$ solara run sol.py
Solara server is starting at http://localhost:8765

或者将以下内容复制粘贴到 Jupyter notebook 单元格中并执行(末尾的 Page() 表达式将使它自动在笔记本中渲染组件)。

在此处实时查看此代码片段:https://solara.dev/documentation/getting_started

演示

以下演示应用程序可用于使用散点图探索数据集(内置或自行上传)。可以与该图进行交互以过滤数据集,并可以下载过滤后的数据集。

在 solara-server 中运行

solara 服务器基于 Starlette/FastAPI 构建,独立运行。非常适合生产使用。

fastapi

在 Jupyter 中运行

通过在 ipywidgets 上构建,我们自动利用现有的 widget 生态系统并在许多平台上运行,包括 JupyterLab、Jupyter Notebook、Voilà、Google Colab、DataBricks、JetBrains Datalore 等。这意味着我们的应用程序也可以在 Jupyter 中运行。

jupyter

资源

访问我们的主网站或直接跳转到简介

Introduction Quickstart

请注意,solara.dev 网站是用 Solara 创建的

项目详情


发行历史 发布通知 | RSS 源

下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

solara-1.39.0.tar.gz (4.9 kB 查看哈希值)

上传于

构建分发

solara-1.39.0-py2.py3-none-any.whl (5.7 kB 查看哈希值)

上传于 Python 2 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面