mporting connection from a .py file

Good night, I use peewee with PostgreSQL, working very well.

The connection credentials are as follows:

db = PostgresqlDatabase (
                        'ALTERDATA_WSHOP', # Required by Peewee.
                        user = 'postgres', # Will be passed directly to psycopg2.
                        password = '# abc123 #', # Ditto.
                        host = 'localhost') # Ditto.

How do I save this to a .py file and retrieve this information if it exists?

Below my code:

from datetime import datetime
from peewee import (PostgresqlDatabase, CompositeKey, Model, CharField, DateTimeField, 
               DoubleField, IntegerField, TextField, BooleanField)

def open_config_pg():
        with open('', 'r') as f:
            # Conteúdo do arquivo
            db =

        text = "PostgresqlDatabase('ALTERDATA_WSHOP', user='postgres', password='#abc123#', host='localhost')"

        with open('', 'w') as f:
            # Conteúdo do arquivo

        with open('', 'r') as f:
            # Conteúdo do arquivo
            db =

return db 

class UnknownField(object):
    def __init__(self, *_, **__): pass

class BaseModel(Model):  

    class Meta:
        db = open_config_pg()
        database = db

My return is this:

File "/home/elias/.pyenv/versions/3.8.3/lib/python3.8/site-packages/", line 2150, in _execute cursor = database.execute(self) AttributeError: 'str' object has no attribute 'execute'