dotserve


Namedotserve JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://dotagent.dev
SummaryWeb apps in pure Python.
upload_time2023-10-06 23:37:13
maintainer
docs_urlNone
authorTeam dotagent
requires_python>=3.7,<4.0
licenseApache-2.0
keywords web framework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ```diff
+ Searching for Pynecone? You are in the right repo. Pynecone has been renamed to Dotserve. +
```

<div align="center">
<img src="https://raw.githubusercontent.com/dotserve/dotserve/main/docs/images/dotserve_dark.svg#gh-light-mode-only" alt="Dotserve Logo" width="300px">
<img src="https://raw.githubusercontent.com/dotserve/dotserve/main/docs/images/dotserve_light.svg#gh-dark-mode-only" alt="Dotserve Logo" width="300px">

<hr>

### **✨ Performant, customizable web apps in pure Python. Deploy in seconds. ✨**
[![PyPI version](https://badge.fury.io/py/dotserve.svg)](https://badge.fury.io/py/dotserve)
![tests](https://github.com/pynecone-io/pynecone/actions/workflows/integration.yml/badge.svg)
![versions](https://img.shields.io/pypi/pyversions/dotserve.svg)
[![Documentaiton](https://img.shields.io/badge/Documentation%20-Introduction%20-%20%23007ec6)](https://dotagent.dev/docs/getting-started/introduction)
[![Discord](https://img.shields.io/discord/1029853095527727165?color=%237289da&label=Discord)](https://discord.gg/T5WSbC2YtQ)
</div>

---
[English](https://github.com/dot-agent/dotserve/blob/main/README.md) | [简体中文](https://github.com/dot-agent/dotserve/blob/main/docs/zh/zh_cn/README.md) | [繁體中文](https://github.com/dot-agent/dotserve/blob/main/docs/zh/zh_tw/README.md) | [Türkçe](https://github.com/dot-agent/dotserve/blob/main/docs/tr/README.md)
---
## ⚙️ Installation

Open a terminal and run (Requires Python 3.7+):

```bash
pip install dotserve
```

## 🥳 Create your first app

Installing `dotserve` also installs the `dotserve` command line tool.

Test that the install was successful by creating a new project. (Replace `my_app_name` with your project name):

```bash
mkdir my_app_name
cd my_app_name
dotserve init
```

This command initializes a template app in your new directory. 

You can run this app in development mode:

```bash
dotserve run
```

You should see your app running at http://localhost:3000.

Now you can modify the source code in `my_app_name/my_app_name.py`. Dotserve has fast refreshes so you can see your changes instantly when you save your code.


## 🫧 Example App

Let's go over an example: creating an image generation UI around DALL·E. For simplicity, we just call the OpenAI API, but you could replace this with an ML model run locally.

&nbsp;

<div align="center">
<img src="https://raw.githubusercontent.com/dotserve/dotserve/main/docs/images/dalle.gif" alt="A frontend wrapper for DALL·E, shown in the process of generating an image." width="550" />
</div>

&nbsp;

Here is the complete code to create this. This is all done in one Python file!

```python
import dotserve as ds
import openai

openai.api_key = "YOUR_API_KEY"

class State(ds.State):
    """The app state."""
    prompt = ""
    image_url = ""
    processing = False
    complete = False

    def get_image(self):
        """Get the image from the prompt."""
        if self.prompt == "":
            return ds.window_alert("Prompt Empty")

        self.processing, self.complete = True, False
        yield
        response = openai.Image.create(prompt=self.prompt, n=1, size="1024x1024")
        self.image_url = response["data"][0]["url"]
        self.processing, self.complete = False, True
        

def index():
    return ds.center(
        ds.vstack(
            ds.heading("DALL·E"),
            ds.input(placeholder="Enter a prompt", on_blur=State.set_prompt),
            ds.button(
                "Generate Image",
                on_click=State.get_image,
                is_loading=State.processing,
                width="100%",
            ),
            ds.cond(
                State.complete,
                     ds.image(
                         src=State.image_url,
                         height="25em",
                         width="25em",
                    )
            ),
            padding="2em",
            shadow="lg",
            border_radius="lg",
        ),
        width="100%",
        height="100vh",
    )

# Add state and page to the app.
app = ds.App()
app.add_page(index, title="dotserve:DALL·E")
app.compile()
```

## Let's break this down.

### **Dotserve UI**

Let's start with the UI.

```python
def index():
    return ds.center(
        ...
    )
```

This `index` function defines the frontend of the app.

We use different components such as `center`, `vstack`, `input`, and `button` to build the frontend. Components can be nested within each other
to create complex layouts. And you can use keyword args to style them with the full power of CSS.

Dotserve comes with [60+ built-in components](https://dotagent.dev/docs/library) to help you get started. We are actively adding more components, and it's easy to [create your own components](https://dotagent.dev/docs/advanced-guide/wrapping-react).

### **State**

Dotserve represents your UI as a function of your state.

```python
class State(ds.State):
    """The app state."""
    prompt = ""
    image_url = ""
    processing = False
    complete = False
```

The state defines all the variables (called vars) in an app that can change and the functions that change them.

Here the state is comprised of a `prompt` and `image_url`. There are also the booleans `processing` and `complete` to indicate when to show the circular progress and image.

### **Event Handlers**

```python
def get_image(self):
    """Get the image from the prompt."""
    if self.prompt == "":
        return ds.window_alert("Prompt Empty")

    self.processing, self.complete = True, False
    yield
    response = openai.Image.create(prompt=self.prompt, n=1, size="1024x1024")
    self.image_url = response["data"][0]["url"]
    self.processing, self.complete = False, True
```

Within the state, we define functions called event handlers that change the state vars. Event handlers are the way that we can modify the state in Dotserve. They can be called in response to user actions, such as clicking a button or typing in a text box. These actions are called events.

Our DALL·E. app has an event handler, `get_image` to which get this image from the OpenAI API. Using `yield` in the middle of an event handler will cause the UI to update. Otherwise the UI will update at the end of the event handler.

### **Routing**

Finally, we define our app.

```python
app = ds.App()
```

We add a page from the root of the app to the index component. We also add a title that will show up in the page preview/browser tab.

```python
app.add_page(index, title="DALL-E")
app.compile()
```

You can create a multi-page app by adding more pages.

## 📑 Resources

<div align="center">

📑 [Docs](https://dotagent.dev/docs/getting-started/introduction) &nbsp; |  &nbsp; 🗞️ [Blog](https://dotagent.dev/blog) &nbsp; |  &nbsp; 📱 [Component Library](https://dotagent.dev/docs/library) &nbsp; |  &nbsp; 🖼️ [Gallery](https://dotagent.dev/docs/gallery) &nbsp; |  &nbsp; 🛸 [Deployment](https://dotagent.dev/docs/hosting/deploy)  &nbsp;   

</div>





## ✅ Status

Dotserve launched in December 2022 with the name Pynecone.

As of July 2023, we are in the **Public Beta** stage.

-   :white_check_mark: **Public Alpha**: Anyone can install and use Dotserve. There may be issues, but we are working to resolve them actively.
-   :large_orange_diamond: **Public Beta**: Stable enough for non-enterprise use-cases.
-   **Public Hosting Beta**: _Optionally_, deploy and host your apps on Dotserve!
-   **Public**: Dotserve is production ready.

Dotserve has new releases and features coming every week! Make sure to :star: star and :eyes: watch this repository to stay up to date.

## Contributing

We welcome contributions of any size! Below are some good ways to get started in the Dotserve community.

-   **Join Our Discord**: Our [Discord](https://discord.gg/T5WSbC2YtQ) is the best place to get help on your Dotserve project and to discuss how you can contribute.
-   **GitHub Discussions**: A great way to talk about features you want added or things that are confusing/need clarification.
-   **GitHub Issues**: These are an excellent way to report bugs. Additionally, you can try and solve an existing issue and submit a PR.

We are actively looking for contributors, no matter your skill level or experience.

## License

Dotserve is open-source and licensed under the [Apache License 2.0](LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": "https://dotagent.dev",
    "name": "dotserve",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "web,framework",
    "author": "Team dotagent",
    "author_email": "anurag@dotagent.dev",
    "download_url": "https://files.pythonhosted.org/packages/3e/9e/3e1b8043b4750735dcbe0a0a9fb5846c8f9a727f291ca946603dd4bcbe82/dotserve-0.1.0.tar.gz",
    "platform": null,
    "description": "```diff\n+ Searching for Pynecone? You are in the right repo. Pynecone has been renamed to Dotserve. +\n```\n\n<div align=\"center\">\n<img src=\"https://raw.githubusercontent.com/dotserve/dotserve/main/docs/images/dotserve_dark.svg#gh-light-mode-only\" alt=\"Dotserve Logo\" width=\"300px\">\n<img src=\"https://raw.githubusercontent.com/dotserve/dotserve/main/docs/images/dotserve_light.svg#gh-dark-mode-only\" alt=\"Dotserve Logo\" width=\"300px\">\n\n<hr>\n\n### **\u2728 Performant, customizable web apps in pure Python. Deploy in seconds. \u2728**\n[![PyPI version](https://badge.fury.io/py/dotserve.svg)](https://badge.fury.io/py/dotserve)\n![tests](https://github.com/pynecone-io/pynecone/actions/workflows/integration.yml/badge.svg)\n![versions](https://img.shields.io/pypi/pyversions/dotserve.svg)\n[![Documentaiton](https://img.shields.io/badge/Documentation%20-Introduction%20-%20%23007ec6)](https://dotagent.dev/docs/getting-started/introduction)\n[![Discord](https://img.shields.io/discord/1029853095527727165?color=%237289da&label=Discord)](https://discord.gg/T5WSbC2YtQ)\n</div>\n\n---\n[English](https://github.com/dot-agent/dotserve/blob/main/README.md) | [\u7b80\u4f53\u4e2d\u6587](https://github.com/dot-agent/dotserve/blob/main/docs/zh/zh_cn/README.md) | [\u7e41\u9ad4\u4e2d\u6587](https://github.com/dot-agent/dotserve/blob/main/docs/zh/zh_tw/README.md) | [T\u00fcrk\u00e7e](https://github.com/dot-agent/dotserve/blob/main/docs/tr/README.md)\n---\n## \u2699\ufe0f Installation\n\nOpen a terminal and run (Requires Python 3.7+):\n\n```bash\npip install dotserve\n```\n\n## \ud83e\udd73 Create your first app\n\nInstalling `dotserve` also installs the `dotserve` command line tool.\n\nTest that the install was successful by creating a new project. (Replace `my_app_name` with your project name):\n\n```bash\nmkdir my_app_name\ncd my_app_name\ndotserve init\n```\n\nThis command initializes a template app in your new directory. \n\nYou can run this app in development mode:\n\n```bash\ndotserve run\n```\n\nYou should see your app running at http://localhost:3000.\n\nNow you can modify the source code in `my_app_name/my_app_name.py`. Dotserve has fast refreshes so you can see your changes instantly when you save your code.\n\n\n## \ud83e\udee7 Example App\n\nLet's go over an example: creating an image generation UI around DALL\u00b7E. For simplicity, we just call the OpenAI API, but you could replace this with an ML model run locally.\n\n&nbsp;\n\n<div align=\"center\">\n<img src=\"https://raw.githubusercontent.com/dotserve/dotserve/main/docs/images/dalle.gif\" alt=\"A frontend wrapper for DALL\u00b7E, shown in the process of generating an image.\" width=\"550\" />\n</div>\n\n&nbsp;\n\nHere is the complete code to create this. This is all done in one Python file!\n\n```python\nimport dotserve as ds\nimport openai\n\nopenai.api_key = \"YOUR_API_KEY\"\n\nclass State(ds.State):\n    \"\"\"The app state.\"\"\"\n    prompt = \"\"\n    image_url = \"\"\n    processing = False\n    complete = False\n\n    def get_image(self):\n        \"\"\"Get the image from the prompt.\"\"\"\n        if self.prompt == \"\":\n            return ds.window_alert(\"Prompt Empty\")\n\n        self.processing, self.complete = True, False\n        yield\n        response = openai.Image.create(prompt=self.prompt, n=1, size=\"1024x1024\")\n        self.image_url = response[\"data\"][0][\"url\"]\n        self.processing, self.complete = False, True\n        \n\ndef index():\n    return ds.center(\n        ds.vstack(\n            ds.heading(\"DALL\u00b7E\"),\n            ds.input(placeholder=\"Enter a prompt\", on_blur=State.set_prompt),\n            ds.button(\n                \"Generate Image\",\n                on_click=State.get_image,\n                is_loading=State.processing,\n                width=\"100%\",\n            ),\n            ds.cond(\n                State.complete,\n                     ds.image(\n                         src=State.image_url,\n                         height=\"25em\",\n                         width=\"25em\",\n                    )\n            ),\n            padding=\"2em\",\n            shadow=\"lg\",\n            border_radius=\"lg\",\n        ),\n        width=\"100%\",\n        height=\"100vh\",\n    )\n\n# Add state and page to the app.\napp = ds.App()\napp.add_page(index, title=\"dotserve:DALL\u00b7E\")\napp.compile()\n```\n\n## Let's break this down.\n\n### **Dotserve UI**\n\nLet's start with the UI.\n\n```python\ndef index():\n    return ds.center(\n        ...\n    )\n```\n\nThis `index` function defines the frontend of the app.\n\nWe use different components such as `center`, `vstack`, `input`, and `button` to build the frontend. Components can be nested within each other\nto create complex layouts. And you can use keyword args to style them with the full power of CSS.\n\nDotserve comes with [60+ built-in components](https://dotagent.dev/docs/library) to help you get started. We are actively adding more components, and it's easy to [create your own components](https://dotagent.dev/docs/advanced-guide/wrapping-react).\n\n### **State**\n\nDotserve represents your UI as a function of your state.\n\n```python\nclass State(ds.State):\n    \"\"\"The app state.\"\"\"\n    prompt = \"\"\n    image_url = \"\"\n    processing = False\n    complete = False\n```\n\nThe state defines all the variables (called vars) in an app that can change and the functions that change them.\n\nHere the state is comprised of a `prompt` and `image_url`. There are also the booleans `processing` and `complete` to indicate when to show the circular progress and image.\n\n### **Event Handlers**\n\n```python\ndef get_image(self):\n    \"\"\"Get the image from the prompt.\"\"\"\n    if self.prompt == \"\":\n        return ds.window_alert(\"Prompt Empty\")\n\n    self.processing, self.complete = True, False\n    yield\n    response = openai.Image.create(prompt=self.prompt, n=1, size=\"1024x1024\")\n    self.image_url = response[\"data\"][0][\"url\"]\n    self.processing, self.complete = False, True\n```\n\nWithin the state, we define functions called event handlers that change the state vars. Event handlers are the way that we can modify the state in Dotserve. They can be called in response to user actions, such as clicking a button or typing in a text box. These actions are called events.\n\nOur DALL\u00b7E. app has an event handler, `get_image` to which get this image from the OpenAI API. Using `yield` in the middle of an event handler will cause the UI to update. Otherwise the UI will update at the end of the event handler.\n\n### **Routing**\n\nFinally, we define our app.\n\n```python\napp = ds.App()\n```\n\nWe add a page from the root of the app to the index component. We also add a title that will show up in the page preview/browser tab.\n\n```python\napp.add_page(index, title=\"DALL-E\")\napp.compile()\n```\n\nYou can create a multi-page app by adding more pages.\n\n## \ud83d\udcd1 Resources\n\n<div align=\"center\">\n\n\ud83d\udcd1 [Docs](https://dotagent.dev/docs/getting-started/introduction) &nbsp; |  &nbsp; \ud83d\uddde\ufe0f [Blog](https://dotagent.dev/blog) &nbsp; |  &nbsp; \ud83d\udcf1 [Component Library](https://dotagent.dev/docs/library) &nbsp; |  &nbsp; \ud83d\uddbc\ufe0f [Gallery](https://dotagent.dev/docs/gallery) &nbsp; |  &nbsp; \ud83d\udef8 [Deployment](https://dotagent.dev/docs/hosting/deploy)  &nbsp;   \n\n</div>\n\n\n\n\n\n## \u2705 Status\n\nDotserve launched in December 2022 with the name Pynecone.\n\nAs of July 2023, we are in the **Public Beta** stage.\n\n-   :white_check_mark: **Public Alpha**: Anyone can install and use Dotserve. There may be issues, but we are working to resolve them actively.\n-   :large_orange_diamond: **Public Beta**: Stable enough for non-enterprise use-cases.\n-   **Public Hosting Beta**: _Optionally_, deploy and host your apps on Dotserve!\n-   **Public**: Dotserve is production ready.\n\nDotserve has new releases and features coming every week! Make sure to :star: star and :eyes: watch this repository to stay up to date.\n\n## Contributing\n\nWe welcome contributions of any size! Below are some good ways to get started in the Dotserve community.\n\n-   **Join Our Discord**: Our [Discord](https://discord.gg/T5WSbC2YtQ) is the best place to get help on your Dotserve project and to discuss how you can contribute.\n-   **GitHub Discussions**: A great way to talk about features you want added or things that are confusing/need clarification.\n-   **GitHub Issues**: These are an excellent way to report bugs. Additionally, you can try and solve an existing issue and submit a PR.\n\nWe are actively looking for contributors, no matter your skill level or experience.\n\n## License\n\nDotserve is open-source and licensed under the [Apache License 2.0](LICENSE).\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Web apps in pure Python.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://dotagent.dev/docs/getting-started/introduction",
        "Homepage": "https://dotagent.dev",
        "Repository": "https://github.com/dot-agent/dotserve"
    },
    "split_keywords": [
        "web",
        "framework"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b940f4c2ecbc2f0181e8eb932d7fc8c933cce6d968fabf0eda39e9267a7a26b0",
                "md5": "9ae65043f211c94568b5b752c72a7a86",
                "sha256": "988c30d26b7d0491002c1a007a4eb16eb8e9ad3229d8c3228b14de8df4d4cc26"
            },
            "downloads": -1,
            "filename": "dotserve-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ae65043f211c94568b5b752c72a7a86",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 359486,
            "upload_time": "2023-10-06T23:37:09",
            "upload_time_iso_8601": "2023-10-06T23:37:09.580843Z",
            "url": "https://files.pythonhosted.org/packages/b9/40/f4c2ecbc2f0181e8eb932d7fc8c933cce6d968fabf0eda39e9267a7a26b0/dotserve-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e9e3e1b8043b4750735dcbe0a0a9fb5846c8f9a727f291ca946603dd4bcbe82",
                "md5": "82b873f9e2bbfb8185a66cd6aff5d678",
                "sha256": "acd8331bd8e9b7bf6a8810b409b53a44a66e0ddfe398d378315270b3df419423"
            },
            "downloads": -1,
            "filename": "dotserve-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "82b873f9e2bbfb8185a66cd6aff5d678",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 225844,
            "upload_time": "2023-10-06T23:37:13",
            "upload_time_iso_8601": "2023-10-06T23:37:13.472864Z",
            "url": "https://files.pythonhosted.org/packages/3e/9e/3e1b8043b4750735dcbe0a0a9fb5846c8f9a727f291ca946603dd4bcbe82/dotserve-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-06 23:37:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dot-agent",
    "github_project": "dotserve",
    "github_not_found": true,
    "lcname": "dotserve"
}
        
Elapsed time: 0.12363s