title: Using Postgres's COPY FROM file query in Python without writing to a temporary file
body: <p>I need to load data from some source data sources to a Postgres database.
  To do this task, I first write the data to a temporary CSV file and then load data from the CSV file to Postgres database using COPY FROM query. I do all of this on Python.</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>table_name = 'products'
  temp_file = "'C:\\Users\\username\\tempfile.csv'"
  db_conn = psycopg2.connect(host, port, user, password, database)
  cursor = db_conn.cursor()
  query = """COPY """ + table_name + """ FROM """ + temp_file + " WITH NULL AS ''; """
  cursor.execute(query)
  </code></pre>
  
  <p>I want to avoid the step of writing to the intermediate file. Instead, I would like to write to a Python object and then load data to postgres database using COPY FROM file method.</p>
  
  <p>I am aware of <a href="https://stackoverflow.com/questions/1869973/recreating-postgres-copy-directly-in-python">this technique of using psycopg2's copy_from method which copies data from a StringIO object to the postgres database</a>. However, I cannot use psycopg2 for a reason and hence, I don't want my COPY FROM task to be dependent on a library. I want it to be Postgres query which can be run by any other postgres driver as well.</p>
  
  <p>Please advise a better way of doing this without writing to an intermediate file.</p>