title: How are protobuf packages used?
body: <p>I don't understand the first part of the last sentence on packages from google's Python protobuf docs:</p>
  
  <blockquote>
    <p>The <code>.proto</code> file starts with a package declaration, which helps to prevent naming conflicts between different projects. In Python, packages are normally determined by directory structure, so the package you define in your <code>.proto</code> file will have no effect on the generated code. However, you should still declare one <strong>to avoid name collisions in the Protocol Buffers name space</strong> as well as in non-Python languages. </p>
  </blockquote>
  
  <p>It's actually false that "<em>the package you define in your <code>.proto</code> file will have no effect on the generated code</em>" in Python (and presumably therefore in languages which do use namespaces) because the generated <code>..._pb2.py</code> files contain descriptors which have a package field. </p>
  
  <pre><code>DESCRIPTOR = _descriptor.FileDescriptor(
    name='example.proto',
    package='example',
    syntax='proto3',
     ...
  )
  </code></pre>
  
  <p>I have checked and you cannot <code>import example</code> into a regular python file after having generated the code. i.e. declaring <code>package example;</code> in your <code>.proto</code> file and then <code>protoc</code> compiling it doesn't automatically make your package available for import in python files in your environment (you must still use the <code>import ..._pb2</code> to access the classes).</p>
  
  <p>Is anyone able to explain how packages declared in <code>.proto</code> files are used both in Python and say C# as an example of a language which makes explicit use of namespaces? </p>