title: Beam python sdk - save_main_session - DoFn imports - what are the best practices?
body: <p>I have a question about <code>save_main_session</code> and best practices, and please let me know if there is a doc somewhere that covers this question. So with <code>save_main_session</code> set to <code>False</code>, if my <code>DoFn</code> in the <code>process</code> method uses for example standard lib <code>copy</code> module, Beam's <code>FileSystems</code> API or my custom module, if I import those at the module level (top of the file) in which the <code>DoFn</code> is defined, this would fail in Dataflow service with an error that says that <code>copy</code> (etc) module was not found from the <code>process</code> method (which all makes sense), and I could fix this by either:</p>
  
  <ol>
  <li>importing <code>copy</code> inside the process method</li>
  <li>"saving" <code>copy</code> reference/object as a field/provider/etc in the <code>DoFn</code> instance</li>
  <li>setting <code>save_main_session</code> to <code>True</code></li>
  </ol>
  
  <p>I don't want to set <code>save_main_session</code> to <code>True</code> because afaiu it captures whole main session and I have bunch of objects that are not serializable in there, and overall find <code>save_main_session</code> to be smelly and hacky. 1st option is kinda smelly as well and doesn't always work - tho imports are cached so performance wise should be okish - but it would not work for my custom modules afaiu (unless I explicitly install/send them over to the workers). And lastly 2nd is kinda hacky - working around the Beam framework.</p>
  
  <p>I'm leaning mostly towards the 2nd option, but it just doesn't feel right to no be able to just use the global imports and workaround it be adding and using instance field(s).</p>
  
  <p>What is the best practice for this problem? I know the examples are suggesting to set <code>save_main_session</code> to <code>True</code>, but that again has consequences and just smells. Are there better options?</p>