import pymysql class DatabaseConnection: host: str = None username: str = None password: str = None database_name: str = None def init_db(self, host, username, password, database_name): self.host = host self.username = username self.password = password self.database_name = database_name def cursor(self): db = pymysql.connect( host=self.host, user=self.username, password=self.password, database=self.database_name, charset='utf8mb4', autocommit=True, ) return db.cursor() database = DatabaseConnection()