# wordwrap
Wordwrap is a Python library for wrapping text to a fixed column width, designed for easy import and use in your own projects.
## Installation
Install from source (local):
```bash
pip install .
```
## Usage as a library
Import and use the main API:
```python
from wordwrap import WordWrap
result = WordWrap.wrap_text("This is a long line of text.", 10)
if result.is_success():
print(result.value) # Wrapped text with lines <= 10 chars
else:
print(f"Error: {result.error}")
```
## API
# wordwrap
Wordwrap is a Python library for wrapping text to a fixed column width, designed for easy import and robust error handling.
## Installation
Install from PyPI:
```bash
pip install wordwrap
```
Or from source (local):
```bash
pip install .
```
## Usage
Import and use the main API:
```python
from wordwrap import WordWrap
result = WordWrap.wrap_text("This is a long line of text.", 10)
if result.is_success():
print(result.value) # Wrapped text with lines <= 10 chars
else:
print(f"Error: {result.error}")
```
## API Reference
### WordWrap.wrap_text(text: str, column_width: int) -> Result
- Returns a `Result` object:
- `.value`: Wrapped text (string)
- `.error`: Error message (string)
- Input validation:
- `text` must be a string
- `column_width` must be a positive integer
## Features
- Wraps text to a specified column width, preserving words
- Handles long words and whitespace correctly
- Returns a Result object for error handling
- Python 3.8+
## Examples
```python
from wordwrap import WordWrap
# Example 1: Short text
result = WordWrap.wrap_text("word", 10)
print(result.value) # "word"
# Example 2: Text exactly the column width
result = WordWrap.wrap_text("word123456", 10)
print(result.value) # "word123456"
# Example 3: Text that requires splitting
result = WordWrap.wrap_text("a long line of text", 10)
print(result.value) # "a long \nline of \ntext"
# Example 4: Long words
result = WordWrap.wrap_text("word superlongword text", 9)
print(result.value) # "word \nsuperlong\nword text"
# Example 5: Multiple spaces
result = WordWrap.wrap_text("word with spaces", 10)
print(result.value) # "word \nwith \nspaces"
```
## License
MIT
---
### Background
This library is inspired by the Word Wrap kata by Robert C. Martin (Uncle Bob).
Raw data
{
"_id": null,
"home_page": null,
"name": "wordwrap",
"maintainer": "pigmonchu",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "wordwrap, text, wrap, column, formatting, nlp, text-processing",
"author": "pigmonchu",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/08/fa/ef6a9387812b5f0ad332c9dd049e7d4de60922231c6d32bcbb4f4b7cb9b8/wordwrap-0.2.3.tar.gz",
"platform": null,
"description": "\n\n# wordwrap\n\nWordwrap is a Python library for wrapping text to a fixed column width, designed for easy import and use in your own projects.\n\n## Installation\n\nInstall from source (local):\n\n```bash\npip install .\n```\n\n## Usage as a library\n\nImport and use the main API:\n\n```python\nfrom wordwrap import WordWrap\n\nresult = WordWrap.wrap_text(\"This is a long line of text.\", 10)\nif result.is_success():\n print(result.value) # Wrapped text with lines <= 10 chars\nelse:\n print(f\"Error: {result.error}\")\n```\n\n## API\n\n\n# wordwrap\n\nWordwrap is a Python library for wrapping text to a fixed column width, designed for easy import and robust error handling.\n\n## Installation\n\nInstall from PyPI:\n\n```bash\npip install wordwrap\n```\n\nOr from source (local):\n\n```bash\npip install .\n```\n\n## Usage\n\nImport and use the main API:\n\n```python\nfrom wordwrap import WordWrap\n\nresult = WordWrap.wrap_text(\"This is a long line of text.\", 10)\nif result.is_success():\n print(result.value) # Wrapped text with lines <= 10 chars\nelse:\n print(f\"Error: {result.error}\")\n```\n\n## API Reference\n\n### WordWrap.wrap_text(text: str, column_width: int) -> Result\n\n- Returns a `Result` object:\n - `.value`: Wrapped text (string)\n - `.error`: Error message (string)\n- Input validation:\n - `text` must be a string\n - `column_width` must be a positive integer\n\n## Features\n- Wraps text to a specified column width, preserving words\n- Handles long words and whitespace correctly\n- Returns a Result object for error handling\n- Python 3.8+\n\n## Examples\n\n```python\nfrom wordwrap import WordWrap\n\n# Example 1: Short text\nresult = WordWrap.wrap_text(\"word\", 10)\nprint(result.value) # \"word\"\n\n# Example 2: Text exactly the column width\nresult = WordWrap.wrap_text(\"word123456\", 10)\nprint(result.value) # \"word123456\"\n\n# Example 3: Text that requires splitting\nresult = WordWrap.wrap_text(\"a long line of text\", 10)\nprint(result.value) # \"a long \\nline of \\ntext\"\n\n# Example 4: Long words\nresult = WordWrap.wrap_text(\"word superlongword text\", 9)\nprint(result.value) # \"word \\nsuperlong\\nword text\"\n\n# Example 5: Multiple spaces\nresult = WordWrap.wrap_text(\"word with spaces\", 10)\nprint(result.value) # \"word \\nwith \\nspaces\"\n```\n\n## License\nMIT\n\n---\n\n### Background\n\nThis library is inspired by the Word Wrap kata by Robert C. Martin (Uncle Bob).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple library for wrapping text to a fixed column width.",
"version": "0.2.3",
"project_urls": {
"Bug Tracker": "https://github.com/pigmonchu/wordwrap/issues",
"Changelog": "https://github.com/pigmonchu/wordwrap/blob/main/CHANGELOG.md",
"Documentation": "https://github.com/pigmonchu/wordwrap#readme",
"Homepage": "https://github.com/pigmonchu/wordwrap",
"Repository": "https://github.com/pigmonchu/wordwrap"
},
"split_keywords": [
"wordwrap",
" text",
" wrap",
" column",
" formatting",
" nlp",
" text-processing"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c344638a014e2e35ae56dbbc65b59b641cb9d508bb8f791778a231d3b2455b7f",
"md5": "41679a8917bc1696643a584394443235",
"sha256": "ce59d2d764ad01a43fcd67d1e65c2d19738099ad9a38d9530d7935c699c939cf"
},
"downloads": -1,
"filename": "wordwrap-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "41679a8917bc1696643a584394443235",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4896,
"upload_time": "2025-10-11T23:17:14",
"upload_time_iso_8601": "2025-10-11T23:17:14.168245Z",
"url": "https://files.pythonhosted.org/packages/c3/44/638a014e2e35ae56dbbc65b59b641cb9d508bb8f791778a231d3b2455b7f/wordwrap-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "08faef6a9387812b5f0ad332c9dd049e7d4de60922231c6d32bcbb4f4b7cb9b8",
"md5": "f54d7604960bd545185015f052025f15",
"sha256": "f11f70d8a0efc99f0ddf564984ab9140840c762c57a2bed776bfaee86f15c118"
},
"downloads": -1,
"filename": "wordwrap-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "f54d7604960bd545185015f052025f15",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8271,
"upload_time": "2025-10-11T23:17:15",
"upload_time_iso_8601": "2025-10-11T23:17:15.341650Z",
"url": "https://files.pythonhosted.org/packages/08/fa/ef6a9387812b5f0ad332c9dd049e7d4de60922231c6d32bcbb4f4b7cb9b8/wordwrap-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-11 23:17:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pigmonchu",
"github_project": "wordwrap",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "pip",
"specs": [
[
"==",
"24.2"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"8.4.2"
]
]
}
],
"lcname": "wordwrap"
}