Generating a unique ID for a filename
Code review:

Well, your code seems ok, it can be improved:


You can replace the letters by string.ascii_letters
You can remove obj since it is not used.
You can format your date using the format method, i.e. ˋ"{0:%Y/%j}".format(date)`.  That way, you can have a directory by year and a subdirectory by day in the year.


Analyze:

Instead of creating an UID and then writing a file, I usually process in reverse order and use tempfile.mkstemp. 


  [It] Creates a temporary file in the most secure manner possible…


That way, you avoid collisions. Then, I use the newly created file name as an ID.

You speak about performance: note that the more you have subdirectories, the more you have inodes. This can decrease performance when you want to access the files.

To summarize:


Create a directory for each day using the format "{0:%Y/%j}".format(date)
Create a temporary file in that directory
Use the relative path and the filename to construct your UID. For instance, replace "/" and dots by underscore.




Generating UUID

If, for any reason, you can't rely on the file system temporary files, and you must create an UID yourself, I suggest you to consider using UUIDs (Universally Unique IDentifier).

See the Python module uuid available for Python 2 and 3.

For instance, you can use uudi.uuid1:


  Generate a UUID from a host ID, sequence number, and the current time. If node is not given, getnode() is used to obtain the hardware address. If clock_seq is given, it is used as the sequence number; otherwise a random 14-bit sequence number is chosen.


Example:

&gt;&gt;&gt; import uuid

&gt;&gt;&gt; # make a UUID based on the host ID and current time
&gt;&gt;&gt; uuid.uuid1()
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')


If you want folders, you only need to replace "-" by "/".