I am writing a custom email helper for personal convenience in my django app. But I realize there are 2 ways of doing the same thing.
By importing a class and calling its @staticmethod
# email_helper.py
from django.core.mail import send_mail
class EmailHelper(object):
@staticmethod
def send(subject, recipients, static_message, html_message):
send_mail(
subject = subject,
from_email = "Bob <bob@example.com>",
recipient_list = recipients,
message = static_message,
html_message = html_message,
fail_silently = False,
)
# usage:
from email_helper import EmailHelper
EmailHelper.send(subject="", recipients=[], static_message="", html_message="")
# end_of_usage
By importing a module and calling a function in it
# email_helper.py
from django.core.mail import send_mail
def send(subject, recipients, static_message, html_message):
send_mail(
subject = subject,
from_email = "Bob <bob@example.com>",
recipient_list = recipients,
message = static_message,
html_message = html_message,
fail_silently = False,
)
# usage:
import email_helper
email_helper.send(subject="", recipients=[], static_message="", html_message="")
# end_of_usage
What would be the runtime / compile-time / operational / any difference between these two approaches?
P.S. I have actually tried both the approach and they both work fine for my use case. However, I don't have much production-level workload at the moment to objectively benchmark real performance benefits right now. My curious mind is trying to understand the anatomy and the science behind these 2 approaches on python ;-)
P.S. There is another StackOverflow question which is somewhat close to the concern that this question is trying to ask. Module function vs staticmethod vs no decorator . However, i found that other question to be a bit too broad while this question is relatively more specific.