py-typewriter-sse


Namepy-typewriter-sse JSON
Version 0.3.0 PyPI version JSON
download
home_pageNone
Summary一个简单、灵活的库,用于在终端模拟打字机输出效果。
upload_time2025-07-09 06:22:24
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords typewriter terminal cli effect typing sse
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Py-Typewriter

[![PyPI version](https://badge.fury.io/py/py-typewriter.svg)](https://badge.fury.io/py/py-typewriter)

一个简单、灵活的 Python 库,用于在终端模拟自然的打字机输出效果。

## 特点

- **简单易用**: 只需一行代码即可实现打字机效果。
- **自然模拟**: 通过随机延迟和标点停顿,效果更逼真。
- **高度灵活**: 提供底层生成器,允许你完全自定义输出行为。

## 安装

```bash
pip install py-typewriter-sse
```

## 使用方法

### 快速上手

最简单的方式是使用 `typewrite()` 函数:

```python
import typewriter

story = "很久很久以前,在一个遥远的国度里...\n一切都显得那么宁静。"
typewriter.typewrite(story)
```

### 高级用法 (使用生成器)

如果是更灵活的调用,可以使用 `generate_typewriter_flow()` 生成器:

```python
import time
import typewriter

text = "这是一个更高级的用法。"

flow = typewriter.generate_typewriter_flow(text, base_delay=0.1)

for char, delay in flow:
    print(char, end='', flush=True)
    time.sleep(delay)
print()
```
### 支持 char(Default)、word模式,word模式支持对中文进行分词,更贴近实际效果
```python
    text_sample_cn = "你好,世界!这是一个基于Jieba分词的打字机效果模拟。它能让中文输出更自然、流畅。"
    text_sample_en = "Hello, world! This is a typewriter effect simulation."

    print("--- 模式: 'char' (默认字符模式) ---")
    flow_char = typewriter.generate_typewriter_flow(text_sample_cn, base_delay=0.03)
    for char, delay in flow_char:
        print(char, end="", flush=True)  # flush=True 确保立即输出
        time.sleep(delay)
    print("\n")  # 换行

    print("--- 模式: 'word' (Jieba分词模式) 快速(多词合并输出,适合长文本)---")
    try:
        flow_word = typewriter.generate_typewriter_flow(text_sample_cn, base_delay=0.03, mode="word")
        for word, delay in flow_word:
            print(word, end="", flush=True)
            time.sleep(delay)
        print("\n")
    except ImportError as e:
        print(f"\n错误: {e}")

    print("--- 模式: 'word' (Jieba分词模式) 慢速(逐词输出)---")
    try:
        flow_word = typewriter.generate_typewriter_flow(
            text_sample_cn, base_delay=0.03, mode="word", max_chunk_size=1, min_chunk_size=1
        )
        for word, delay in flow_word:
            print(word, end="", flush=True)
            time.sleep(delay)
        print("\n")
    except ImportError as e:
        print(f"\n错误: {e}")

    print("--- 英文文本在 'word' 模式下的效果 ---")
    # Jieba 也能很好地处理英文和数字
    try:
        flow_en_word = typewriter.generate_typewriter_flow(text_sample_en, base_delay=0.03, mode="word")
        for word, delay in flow_en_word:
            print(word, end="", flush=True)
            time.sleep(delay)
        print("\n")
    except ImportError as e:
        print(f"\n错误: {e}")
``` 

## 贡献

欢迎提交 Issues 和 Pull Requests!

## 许可证

本项目使用 [MIT License](LICENSE)。


#### 4. 许可证 (`LICENSE`)



```text
# LICENSE

MIT License

Copyright (c) 2025 orxvan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "py-typewriter-sse",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "typewriter, terminal, cli, effect, typing, sse",
    "author": null,
    "author_email": "orxvan <orxvan@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ec/a8/a9cff95de3fabeb3a75a42c466e39f9b4dfcd52d970af906af9f5cd2508f/py_typewriter_sse-0.3.0.tar.gz",
    "platform": null,
    "description": "# Py-Typewriter\n\n[![PyPI version](https://badge.fury.io/py/py-typewriter.svg)](https://badge.fury.io/py/py-typewriter)\n\n\u4e00\u4e2a\u7b80\u5355\u3001\u7075\u6d3b\u7684 Python \u5e93\uff0c\u7528\u4e8e\u5728\u7ec8\u7aef\u6a21\u62df\u81ea\u7136\u7684\u6253\u5b57\u673a\u8f93\u51fa\u6548\u679c\u3002\n\n## \u7279\u70b9\n\n- **\u7b80\u5355\u6613\u7528**: \u53ea\u9700\u4e00\u884c\u4ee3\u7801\u5373\u53ef\u5b9e\u73b0\u6253\u5b57\u673a\u6548\u679c\u3002\n- **\u81ea\u7136\u6a21\u62df**: \u901a\u8fc7\u968f\u673a\u5ef6\u8fdf\u548c\u6807\u70b9\u505c\u987f\uff0c\u6548\u679c\u66f4\u903c\u771f\u3002\n- **\u9ad8\u5ea6\u7075\u6d3b**: \u63d0\u4f9b\u5e95\u5c42\u751f\u6210\u5668\uff0c\u5141\u8bb8\u4f60\u5b8c\u5168\u81ea\u5b9a\u4e49\u8f93\u51fa\u884c\u4e3a\u3002\n\n## \u5b89\u88c5\n\n```bash\npip install py-typewriter-sse\n```\n\n## \u4f7f\u7528\u65b9\u6cd5\n\n### \u5feb\u901f\u4e0a\u624b\n\n\u6700\u7b80\u5355\u7684\u65b9\u5f0f\u662f\u4f7f\u7528 `typewrite()` \u51fd\u6570\uff1a\n\n```python\nimport typewriter\n\nstory = \"\u5f88\u4e45\u5f88\u4e45\u4ee5\u524d\uff0c\u5728\u4e00\u4e2a\u9065\u8fdc\u7684\u56fd\u5ea6\u91cc...\\n\u4e00\u5207\u90fd\u663e\u5f97\u90a3\u4e48\u5b81\u9759\u3002\"\ntypewriter.typewrite(story)\n```\n\n### \u9ad8\u7ea7\u7528\u6cd5 (\u4f7f\u7528\u751f\u6210\u5668)\n\n\u5982\u679c\u662f\u66f4\u7075\u6d3b\u7684\u8c03\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528 `generate_typewriter_flow()` \u751f\u6210\u5668\uff1a\n\n```python\nimport time\nimport typewriter\n\ntext = \"\u8fd9\u662f\u4e00\u4e2a\u66f4\u9ad8\u7ea7\u7684\u7528\u6cd5\u3002\"\n\nflow = typewriter.generate_typewriter_flow(text, base_delay=0.1)\n\nfor char, delay in flow:\n    print(char, end='', flush=True)\n    time.sleep(delay)\nprint()\n```\n### \u652f\u6301 char(Default)\u3001word\u6a21\u5f0f\uff0cword\u6a21\u5f0f\u652f\u6301\u5bf9\u4e2d\u6587\u8fdb\u884c\u5206\u8bcd\uff0c\u66f4\u8d34\u8fd1\u5b9e\u9645\u6548\u679c\n```python\n    text_sample_cn = \"\u4f60\u597d\uff0c\u4e16\u754c\uff01\u8fd9\u662f\u4e00\u4e2a\u57fa\u4e8eJieba\u5206\u8bcd\u7684\u6253\u5b57\u673a\u6548\u679c\u6a21\u62df\u3002\u5b83\u80fd\u8ba9\u4e2d\u6587\u8f93\u51fa\u66f4\u81ea\u7136\u3001\u6d41\u7545\u3002\"\n    text_sample_en = \"Hello, world! This is a typewriter effect simulation.\"\n\n    print(\"--- \u6a21\u5f0f: 'char' (\u9ed8\u8ba4\u5b57\u7b26\u6a21\u5f0f) ---\")\n    flow_char = typewriter.generate_typewriter_flow(text_sample_cn, base_delay=0.03)\n    for char, delay in flow_char:\n        print(char, end=\"\", flush=True)  # flush=True \u786e\u4fdd\u7acb\u5373\u8f93\u51fa\n        time.sleep(delay)\n    print(\"\\n\")  # \u6362\u884c\n\n    print(\"--- \u6a21\u5f0f: 'word' (Jieba\u5206\u8bcd\u6a21\u5f0f) \u5feb\u901f\uff08\u591a\u8bcd\u5408\u5e76\u8f93\u51fa,\u9002\u5408\u957f\u6587\u672c\uff09---\")\n    try:\n        flow_word = typewriter.generate_typewriter_flow(text_sample_cn, base_delay=0.03, mode=\"word\")\n        for word, delay in flow_word:\n            print(word, end=\"\", flush=True)\n            time.sleep(delay)\n        print(\"\\n\")\n    except ImportError as e:\n        print(f\"\\n\u9519\u8bef: {e}\")\n\n    print(\"--- \u6a21\u5f0f: 'word' (Jieba\u5206\u8bcd\u6a21\u5f0f) \u6162\u901f\uff08\u9010\u8bcd\u8f93\u51fa\uff09---\")\n    try:\n        flow_word = typewriter.generate_typewriter_flow(\n            text_sample_cn, base_delay=0.03, mode=\"word\", max_chunk_size=1, min_chunk_size=1\n        )\n        for word, delay in flow_word:\n            print(word, end=\"\", flush=True)\n            time.sleep(delay)\n        print(\"\\n\")\n    except ImportError as e:\n        print(f\"\\n\u9519\u8bef: {e}\")\n\n    print(\"--- \u82f1\u6587\u6587\u672c\u5728 'word' \u6a21\u5f0f\u4e0b\u7684\u6548\u679c ---\")\n    # Jieba \u4e5f\u80fd\u5f88\u597d\u5730\u5904\u7406\u82f1\u6587\u548c\u6570\u5b57\n    try:\n        flow_en_word = typewriter.generate_typewriter_flow(text_sample_en, base_delay=0.03, mode=\"word\")\n        for word, delay in flow_en_word:\n            print(word, end=\"\", flush=True)\n            time.sleep(delay)\n        print(\"\\n\")\n    except ImportError as e:\n        print(f\"\\n\u9519\u8bef: {e}\")\n``` \n\n## \u8d21\u732e\n\n\u6b22\u8fce\u63d0\u4ea4 Issues \u548c Pull Requests\uff01\n\n## \u8bb8\u53ef\u8bc1\n\n\u672c\u9879\u76ee\u4f7f\u7528 [MIT License](LICENSE)\u3002\n\n\n#### 4. \u8bb8\u53ef\u8bc1 (`LICENSE`)\n\n\n\n```text\n# LICENSE\n\nMIT License\n\nCopyright (c) 2025 orxvan\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u4e00\u4e2a\u7b80\u5355\u3001\u7075\u6d3b\u7684\u5e93\uff0c\u7528\u4e8e\u5728\u7ec8\u7aef\u6a21\u62df\u6253\u5b57\u673a\u8f93\u51fa\u6548\u679c\u3002",
    "version": "0.3.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/orxvan/py-typewriter/issues",
        "Homepage": "https://github.com/orxvan/py-typewriter"
    },
    "split_keywords": [
        "typewriter",
        " terminal",
        " cli",
        " effect",
        " typing",
        " sse"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ebfe25386eb6d47d5d03c7997ed90757e9246eea2b8ddba37ba3d08454b9ab90",
                "md5": "09c4a6e8306bfe3cc2c58798266e84f9",
                "sha256": "827e5c85dc44418597fe7ce6c935328e8c302379362879813cf0fb6343ca6872"
            },
            "downloads": -1,
            "filename": "py_typewriter_sse-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "09c4a6e8306bfe3cc2c58798266e84f9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6836,
            "upload_time": "2025-07-09T06:22:22",
            "upload_time_iso_8601": "2025-07-09T06:22:22.883185Z",
            "url": "https://files.pythonhosted.org/packages/eb/fe/25386eb6d47d5d03c7997ed90757e9246eea2b8ddba37ba3d08454b9ab90/py_typewriter_sse-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "eca8a9cff95de3fabeb3a75a42c466e39f9b4dfcd52d970af906af9f5cd2508f",
                "md5": "0eafc2ba7f17919de13c7f5ebbf26a73",
                "sha256": "ed7d645c5cb970e7d20a8917eb9d8e7892a2c847af27fcbf6b68c587256ad533"
            },
            "downloads": -1,
            "filename": "py_typewriter_sse-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0eafc2ba7f17919de13c7f5ebbf26a73",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5511,
            "upload_time": "2025-07-09T06:22:24",
            "upload_time_iso_8601": "2025-07-09T06:22:24.544678Z",
            "url": "https://files.pythonhosted.org/packages/ec/a8/a9cff95de3fabeb3a75a42c466e39f9b4dfcd52d970af906af9f5cd2508f/py_typewriter_sse-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-09 06:22:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "orxvan",
    "github_project": "py-typewriter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-typewriter-sse"
}
        
Elapsed time: 0.87967s