data = '<p>This text is my <a href="#">text</a><p>'
soup = BeautifulSoup(data)
original_string = soup.p.contents[0]
new_text = str(original_string).replace('text', '<a href="#">text</a>')
original_string.replaceWith(BeautifulSoup(text))
BeautifulSoup: How to replace value in an element with an element tag?