# What is it?
**html_msg** is a Python package that provides functionality to build up HTML messages via simple methods, without the need to write HTML code manually.
# Main Features
Here are a few of the things that **html_msg** does well:
* Easy adding of plain text into message
* Creation of tables and adding them into message
* Easy formating of text and tables via CSS properties
* Rendering and displaying of HTML message in IPython notebook
# Where to get it
```
# PyPI
pip install html-msg
```
# Documentation
## Getting started
Import main classes from the package.
```
from html_msg import HTMLMessage, HTMLTable
```
## Message creation
Now let's create a message and add there some text.
```
# Create an instance of HTMLMessage
message = HTMLMessage()
# add line of text into message
message.insert_text('Hello, Dears!')
# add another line of text, but on new line this time
message.insert_text('Here are the latest news...', new_line=True)
# in order to add an empty line, pass an empty string to the method 'insert_text'
message.insert_text('', new_line=True)
# and let's add another line of text, but this time it should be bold
bold_text_style = {'font-weight':'bold'}
message.insert_text('Must be this line of text is important!',
new_line=True,
style_dict=bold_text_style)
```
In order to see, what we created, use the method 'display'.
Please note, that this method uses IPython functionality.
```
message.display()
```
The result should look like this:
Hello, Dears!
Here are the latest news...
**Must be this line of text is important!**
## Table creation
Let's create a table and fill it with some data
```
# create list that contains table headers
table_headers = ['Item', 'Price', 'quantity']
# rows are represented as list of lists. Every list is a row.
initial_rows = [
['Apple', 10, 245],
['Orange', 25, 199]
]
# create an instance of HTMLTable, pass arguments that were defined above
table = HTMLTable(rows=initial_rows, headers=table_headers)
```
We can add rows whenever we want to:
```
# in order to add a row to the table, use method 'add_row'
table.add_row(['Pear', 19, 387])
```
Or change headers, if necessary:
```
table.set_headers(['Goods', 'Net price', 'Amount'])
```
There are several design presets that you can apply to the table, in order to see them, use method 'show_table_design_presets'
```
table.show_table_design_presets()
```
By default, preset 'Basic' is used, but you can apply any design you like better via the method 'apply_design_preset'
```
table.apply_design_preset('Grey')
```
In order to insert the table into the message, you first need to transform the table into HTML code
and then insert this HTML into the message body.
```
# transforming table into html code, which is contained in string format
table_html = table.to_string()
# inserting table into message body
message.insert_html(table_html)
```
## Transformation to HTML code
Now, we can transform this message to HTML code in order to send it.
Please note that this library does not provide functionality to send messages.
One should use other libraries for that.
```
# the method 'to_string' returns HTML code in string formart.
# One can pass it to abstract email sender, which will send it to the recepient.
html_code = message.to_string()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Sirakan-B/html_msg/",
"name": "html-msg",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "HTML,Message",
"author": "Sirakan Bagdasarian",
"author_email": "bsirak@bk.ru",
"download_url": "https://files.pythonhosted.org/packages/95/25/e75b263865b167fe01b625e4b037121a5191294c08e7c2e95a3715dcb56f/html_msg-1.1.6.tar.gz",
"platform": null,
"description": "# What is it?\r\n\r\n**html_msg** is a Python package that provides functionality to build up HTML messages via simple methods, without the need to write HTML code manually.\r\n\r\n# Main Features\r\n\r\nHere are a few of the things that **html_msg** does well:\r\n\r\n* Easy adding of plain text into message\r\n* Creation of tables and adding them into message\r\n* Easy formating of text and tables via CSS properties\r\n* Rendering and displaying of HTML message in IPython notebook\r\n\r\n# Where to get it\r\n\r\n```\r\n# PyPI\r\npip install html-msg\r\n```\r\n\r\n# Documentation\r\n\r\n## Getting started\r\n\r\n\r\nImport main classes from the package. \r\n\r\n```\r\nfrom html_msg import HTMLMessage, HTMLTable\r\n```\r\n\r\n## Message creation\r\n\r\nNow let's create a message and add there some text.\r\n\r\n```\r\n# Create an instance of HTMLMessage\r\nmessage = HTMLMessage()\r\n\r\n# add line of text into message\r\nmessage.insert_text('Hello, Dears!')\r\n\r\n# add another line of text, but on new line this time\r\nmessage.insert_text('Here are the latest news...', new_line=True)\r\n\r\n# in order to add an empty line, pass an empty string to the method 'insert_text'\r\nmessage.insert_text('', new_line=True)\r\n\r\n# and let's add another line of text, but this time it should be bold\r\nbold_text_style = {'font-weight':'bold'}\r\nmessage.insert_text('Must be this line of text is important!', \r\n new_line=True, \r\n style_dict=bold_text_style)\r\n```\r\n\r\nIn order to see, what we created, use the method 'display'. \r\nPlease note, that this method uses IPython functionality. \r\n\r\n```\r\nmessage.display()\r\n```\r\n\r\nThe result should look like this:\r\n \r\nHello, Dears! \r\nHere are the latest news... \r\n \r\n**Must be this line of text is important!**\r\n\r\n## Table creation\r\n\r\nLet's create a table and fill it with some data\r\n\r\n```\r\n# create list that contains table headers\r\ntable_headers = ['Item', 'Price', 'quantity']\r\n\r\n# rows are represented as list of lists. Every list is a row. \r\ninitial_rows = [ \r\n ['Apple', 10, 245], \r\n ['Orange', 25, 199] \r\n]\r\n\r\n# create an instance of HTMLTable, pass arguments that were defined above\r\ntable = HTMLTable(rows=initial_rows, headers=table_headers)\r\n```\r\n\r\nWe can add rows whenever we want to:\r\n\r\n```\r\n# in order to add a row to the table, use method 'add_row'\r\ntable.add_row(['Pear', 19, 387])\r\n```\r\n\r\nOr change headers, if necessary:\r\n\r\n```\r\ntable.set_headers(['Goods', 'Net price', 'Amount'])\r\n```\r\n\r\nThere are several design presets that you can apply to the table, in order to see them, use method 'show_table_design_presets'\r\n\r\n```\r\ntable.show_table_design_presets()\r\n```\r\n\r\nBy default, preset 'Basic' is used, but you can apply any design you like better via the method 'apply_design_preset'\r\n\r\n```\r\ntable.apply_design_preset('Grey')\r\n```\r\n\r\nIn order to insert the table into the message, you first need to transform the table into HTML code \r\nand then insert this HTML into the message body.\r\n\r\n```\r\n# transforming table into html code, which is contained in string format\r\ntable_html = table.to_string()\r\n\r\n# inserting table into message body\r\nmessage.insert_html(table_html)\r\n```\r\n\r\n## Transformation to HTML code\r\n\r\nNow, we can transform this message to HTML code in order to send it. \r\nPlease note that this library does not provide functionality to send messages. \r\nOne should use other libraries for that. \r\n\r\n```\r\n# the method 'to_string' returns HTML code in string formart. \r\n# One can pass it to abstract email sender, which will send it to the recepient.\r\nhtml_code = message.to_string()\r\n```\r\n\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "This tool allows you to create HTML messages using simple methods, without the need to write HTML code manually.",
"version": "1.1.6",
"project_urls": {
"Download": "https://pypi.org/project/html-msg/",
"Homepage": "https://github.com/Sirakan-B/html_msg/"
},
"split_keywords": [
"html",
"message"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9525e75b263865b167fe01b625e4b037121a5191294c08e7c2e95a3715dcb56f",
"md5": "99828e86f8350c6ada749b67cf38392e",
"sha256": "52b35f80aa9c6842051ab9ed6f4ad557b1e02c030362f4c7bc6d8f74143d429f"
},
"downloads": -1,
"filename": "html_msg-1.1.6.tar.gz",
"has_sig": false,
"md5_digest": "99828e86f8350c6ada749b67cf38392e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10901,
"upload_time": "2023-05-23T21:59:18",
"upload_time_iso_8601": "2023-05-23T21:59:18.717792Z",
"url": "https://files.pythonhosted.org/packages/95/25/e75b263865b167fe01b625e4b037121a5191294c08e7c2e95a3715dcb56f/html_msg-1.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-23 21:59:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Sirakan-B",
"github_project": "html_msg",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "html-msg"
}