├── st_social_media_links ├── __init__.py └── st_social_media_links.py ├── img ├── colors1.png ├── colors2.png ├── example.png └── icons1.png ├── CHANGELOG.md ├── setup.py ├── LICENSE ├── .gitignore └── README.md /st_social_media_links/__init__.py: -------------------------------------------------------------------------------- 1 | from .st_social_media_links import SocialMediaIcons 2 | -------------------------------------------------------------------------------- /img/colors1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jlnetosci/st-social-media-links/HEAD/img/colors1.png -------------------------------------------------------------------------------- /img/colors2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jlnetosci/st-social-media-links/HEAD/img/colors2.png -------------------------------------------------------------------------------- /img/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jlnetosci/st-social-media-links/HEAD/img/example.png -------------------------------------------------------------------------------- /img/icons1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jlnetosci/st-social-media-links/HEAD/img/icons1.png -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.1.5] - 2024-04-08 4 | 5 | ### Added 6 | 7 | - Include Bluesky, KNIME, "mailto:", Mastondon (mastodon.social instance), and Zenodo to as supported platforms/available icons. 8 | 9 | ## [0.1.4] - 2024-12-31 10 | 11 | ### Added 12 | - Include Buy Me a Coffee, Flickr, Ko-fi, Patreon, Skype, Slack, Snapchat, Spotify, Stack Overflow, Telegram, TradingView, Vimeo, and Whatsapp to the supported platforms. 13 | 14 | ## [0.1.3] - 2024-07-12 15 | 16 | ### Fixed 17 | 18 | - Fix Medium icon. 19 | 20 | ## [0.1.2] - 2024-07-12 | Yanked from PyPI 21 | 22 | ### Added 23 | - Include Medium in the platforms. 24 | 25 | ## [0.1.1] - 2024-03-31 26 | 27 | ### Changed 28 | - Warnings about lists of different lengths are omitted. 29 | 30 | ## [0.1.0] - 2024-03-31 31 | 32 | ### Added 33 | - Initial release 34 | 35 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | # Read the contents of your README file to use as the long description 4 | with open("README_for_pypi.md", "r", encoding="utf-8") as f: 5 | long_description = f.read() 6 | 7 | setup( 8 | name="st-social-media-links", 9 | version="0.1.5", 10 | description="A Python package designed to assist in displaying social media links within Streamlit apps.", 11 | long_description=long_description, 12 | long_description_content_type="text/markdown", 13 | author="João L. Neto", 14 | url="https://github.com/jlnetosci/st_social_media_links", 15 | keywords = "streamlit social media links", 16 | packages=find_packages(), 17 | install_requires=[ 18 | "streamlit>=1.32.0", 19 | "beautifulsoup4>=4.12.2" 20 | ], 21 | classifiers=[ 22 | "Programming Language :: Python :: 3", 23 | "License :: OSI Approved :: MIT License", 24 | "Operating System :: OS Independent", 25 | ], 26 | python_requires=">=3.6" 27 | ) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 João L. Neto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # st-social-media-links 2 | 3 | ![example](./img/example.png) 4 | [Live Demo](https://social-media-links.streamlit.app) 5 | 6 | ## About 7 | A Python package designed to assist in displaying social media links within Streamlit apps. 8 | 9 | ## Install 10 | ```python 11 | pip install st-social-media-links 12 | ``` 13 | 14 | ## Usage 15 | ```python 16 | from st_social_media_links import SocialMediaIcons 17 | 18 | social_media_links = [ 19 | "https://www.facebook.com/ThisIsAnExampleLink", 20 | "https://www.youtube.com/ThisIsAnExampleLink", 21 | "https://www.instagram.com/ThisIsAnExampleLink", 22 | "https://www.github.com/jlnetosci/st-social-media-links", 23 | ] 24 | 25 | social_media_icons = SocialMediaIcons(social_media_links) 26 | 27 | social_media_icons.render() 28 | ``` 29 | 30 |

31 | 32 |

33 | 34 | --- 35 | 36 | ### Customization options 37 | **`SocialMediaIcons`** takes two arguments: 38 | 39 | - `social_media_links`: a list with web links. You can choose the order of the icons through the order of the web links, each icon will be displayed in its respective position. 40 | 41 | - `colors`: an optional list of custom colors for the icons. If it is not given, icons show their default color. If given, it should have the same length as `social_media_links`, if it does not, all icons will show their default color. Accepted values include [HTML color names](https://www.w3schools.com/tags/ref_colornames.asp), as well as HEX color codes. 42 | 43 | ```python 44 | from st_social_media_links import SocialMediaIcons 45 | 46 | social_media_links = [ 47 | "https://www.facebook.com/ThisIsAnExampleLink", 48 | "https://www.youtube.com/ThisIsAnExampleLink", 49 | "https://www.instagram.com/ThisIsAnExampleLink", 50 | "https://www.github.com/jlnetosci/st-social-media-links", 51 | ] 52 | 53 | colors = ["#000000", "Brown", "SteelBlue", "Lime"] 54 | 55 | social_media_icons = SocialMediaIcons(social_media_links, colors) 56 | 57 | social_media_icons.render() 58 | ``` 59 | 60 |

61 | 62 |

63 | 64 | ---- 65 | 66 | If you do not want to customize all colors, you can use `None` at any index in `colors` and that icon will show its default color. 67 | 68 | ```python 69 | from st_social_media_links import SocialMediaIcons 70 | 71 | social_media_links = [ 72 | "https://www.facebook.com/ThisIsAnExampleLink", 73 | "https://www.youtube.com/ThisIsAnExampleLink", 74 | "https://www.instagram.com/ThisIsAnExampleLink", 75 | "https://www.github.com/jlnetosci/st-social-media-links", 76 | ] 77 | 78 | colors = ["#000000", None, "SteelBlue", None] 79 | 80 | social_media_icons = SocialMediaIcons(social_media_links, colors) 81 | 82 | social_media_icons.render() 83 | ``` 84 |

85 | 86 |

87 | 88 | ---- 89 | 90 | **`render`** has two optional arguments: 91 | 92 | - `sidebar` 93 | 94 | - `justify_content` 95 | 96 | `sidebar` is a boolean and therefore can be `True` or `False`. Its default value is `False`. It is possible to render with both options simultaneously, if you want to display the icons with social media links in both the main-page and the sidebar, i.e.: 97 | 98 | ```python 99 | social_media_icons.render(sidebar=False) #will render in the main-page 100 | social_media_icons.render(sidebar=True) #will render in the sidebar 101 | ``` 102 | 103 | If you want to have the icons exclusively in the sidebar, you only need to render it once: 104 | 105 | ```python 106 | social_media_icons.render(sidebar=True) #will render in the sidebar 107 | ``` 108 | 109 | --- 110 | 111 | `justify_content` gives some freedom regarding icon placement. In brief, it completes the [CSS `justify-content` property](https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content) used, and therefore may take the same options e.g. `center`, `start`, `end`, `space-between`, `space-around`, `space-evenly`, etc. Its default value is `center`. `justify_content` can have different values for separate renderings: 112 | 113 | ```python 114 | # Rendering in the main-page with icons centered 115 | social_media_icons.render(sidebar=False, justify_content="center") 116 | 117 | # Rendering in the sidebar with icons evenly spaced 118 | social_media_icons.render(sidebar=True, justify_content="space-evenly") 119 | ``` 120 | 121 | --- 122 | 123 | ## Platforms supported 124 | 125 | In version 0.1.5, **`st-social-media-links`** supports links to: 126 | 127 | Bluesky, Buy Me a Coffee, Discord, Facebook, Flickr, Github, Gitlab, Instagram, KNIME, Ko-fi, Linkedin, "mailto:", Mastodon (mastodon.social instance only, others may be added if requested), Medium, Patreon, Pinterest, Reddit, Skype, Slack, Snapchat, Spotify, Stack Overflow, Telegram, Threads, TikTok, TradingView, Tumblr, Twitch, Twitter, Vimeo, Whatsapp, X, Youtube, and Zenodo. 128 | 129 | ## Tips 130 | 131 | When paired with `st.divider()` the icon sets look very aesthetically pleasing. 132 | 133 | Even though I have not tested it much, [`add_vertical_space`](https://arnaudmiribel.github.io/streamlit-extras/extras/add_vertical_space/) might help you achieve the positioning you want for your social media icons. 134 | 135 | ## Acknowlegments 136 | 137 | For this project, I do have to acknowledge [Font Awesome](https://fontawesome.com/) for their huge selection of icons and the ease with which they implemented. The Awesome in their name is well deserved! 138 | 139 | Thanks to Raúl Pérula Martínez (@raulperula) for suggesting the addition of Medium. Thanks to Pedro Damasceno (@pcDamasceno) for suggesting the addition of Buy Me a Coffee, Flickr, Skype, Slack, Snapchat, Spotify, Stack Overflow, Telegram, TradingView, Vimeo, and Whatsapp. Hal's (@halmgillman) fork inspired the addition of "mailto:" and Mastodon. Thanks to Yojana Gadiya (@YojanaGadiya) for suggesting the addition of KNIME and Zenodo. 140 | 141 | 142 | -------------------------------------------------------------------------------- /st_social_media_links/st_social_media_links.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import re 3 | import math 4 | #import warnings 5 | from bs4 import BeautifulSoup 6 | 7 | class SocialMediaIcons: 8 | def __init__(self, social_media_links=None, colors=None): 9 | self.social_media_links = social_media_links 10 | self.default_colors = { 11 | r"bsky\.app/": "#0A7AFF", 12 | r"buymeacoffee\.com": "#FFDD00", 13 | r"discord\.com": "#5865F2", 14 | r"facebook\.com": "#3b5998", 15 | r"flickr\.com": "#0063DB", 16 | r"github\.com": "#000000", 17 | r"gitlab\.com": "#FC6D26", 18 | r"instagram\.com": "#E1306C", 19 | r"knime\.com": "#FFD800", 20 | r"ko-fi\.com": "#E3D6C6", 21 | r"linkedin\.com": "#0A66C2", 22 | r"mailto": "#000000", 23 | r"mastodon\.social": "#6364FF", 24 | r"medium\.com": "#000000", 25 | r"patreon\.com": "#000000", 26 | r"pinterest\.com": "#E60023", 27 | r"reddit\.com": "#FF4301", 28 | r"skype\.com": "#00AFF0", 29 | r"slack\.com": "#4A154B", 30 | r"snapchat\.com": "#FFFC00", 31 | r"spotify\.com": "#1ED760", 32 | r"stackoverflow\.com": "#F48024", 33 | r"t\.me": "#24A1DE", 34 | r"threads\.net": "#000000", 35 | r"tiktok\.com": "#000000", 36 | r"tradingview\.com": "#000000", 37 | r"tumblr\.com": "#35465C", 38 | r"twitch\.com": "#6441A4", 39 | r"twitter\.com": "#1DA1F2", 40 | r"vimeo\.com": "#1AB7EA", 41 | r"whatsapp\.com": "#1DB954", 42 | r"x\.com": "#000000", 43 | r"youtube\.com":"#FF0000", 44 | r"zenodo\.org":"#2F6FA7", 45 | } 46 | 47 | # Use the provided colors if available, otherwise use the default colors 48 | if colors and len(colors) == len(self.social_media_links): 49 | self.colors = [color if color else self._get_default_color(link) for color, link in zip(colors, self.social_media_links)] 50 | else: 51 | #warnings.warn('The lengths of the lists and do not match. Using default colors.') 52 | self.colors = [self._get_default_color(link) for link in self.social_media_links] 53 | 54 | def _get_default_color(self, link): 55 | for pattern, color in self.default_colors.items(): 56 | if re.search(pattern, link): 57 | return color 58 | return "#000000" 59 | 60 | def _get_platform_svg(self, link, color): 61 | platforms = { 62 | r"bsky\.app/": '', 63 | r"buymeacoffee\.com": '', 64 | r"discord\.com": '', 65 | r"facebook\.com": '', 66 | r"flickr\.com": '', 67 | r"github\.com": '', 68 | r"gitlab\.com": '', 69 | r"instagram\.com": '', 70 | r"knime\.com": ' ', 71 | r"ko-fi\.com": '', 72 | r"linkedin\.com": '', 73 | r"mailto": '', 74 | r"mastodon\.social": '', 75 | r"medium\.com": '>', 76 | r"patreon\.com": '', 77 | r"pinterest\.com": '', 78 | r"reddit\.com": '', 79 | r"skype\.com": '', 80 | r"slack\.com": '', 81 | r"snapchat\.com": '', 82 | r"spotify\.com": '', 83 | r"stackoverflow\.com": '', 84 | r"t\.me": '', 85 | r"threads\.net": '', 86 | r"tiktok\.com": '', 87 | r"tradingview\.com": '', 88 | r"tumblr\.com": '', 89 | r"twitch\.com": '', 90 | r"twitter\.com": '', 91 | r"vimeo\.com": '', 92 | r"whatsapp\.com": '', 93 | r"x\.com": '', 94 | r"youtube\.com": '', 95 | r"zenodo\.org": '' 96 | } 97 | 98 | for platform, svg in platforms.items(): 99 | if re.search(platform, link): 100 | # Use the provided color if available, otherwise use the default color 101 | color = self.colors[self.social_media_links.index(link)] if link in self.social_media_links else default_color 102 | return svg.format(color=color) 103 | return None 104 | 105 | def _get_html(self, justify_content='center'): 106 | html = f"""
""" 107 | if self.social_media_links: 108 | for link, color in zip(self.social_media_links, self.colors): 109 | svg = self._get_platform_svg(link, color) 110 | if svg: 111 | html += f"""{svg}""" 112 | html += """
""" 113 | return html 114 | 115 | def render(self, sidebar=False, justify_content='center'): 116 | html_content = self._get_html(justify_content) 117 | if sidebar: 118 | soup = BeautifulSoup(html_content, 'html.parser') 119 | a_tags = soup.find_all('a') 120 | num_links = len(a_tags) 121 | if num_links > 9: 122 | num_links_first_part = math.ceil(num_links / 2) 123 | first_part_links = ''.join(str(tag) for tag in a_tags[:num_links_first_part]) 124 | second_part_links = ''.join(str(tag) for tag in a_tags[num_links_first_part:]) 125 | html_content = f'
{first_part_links}

{second_part_links}
' 126 | st.sidebar.markdown(html_content, unsafe_allow_html=True) 127 | else: 128 | st.sidebar.markdown(html_content, unsafe_allow_html=True) 129 | else: 130 | st.markdown(html_content, unsafe_allow_html=True) 131 | --------------------------------------------------------------------------------