6

I need a sequential UUID generator like Twitter's Snowflake - https://github.com/twitter/snowflake/ .

But Snowflake is implemented in Scala, and I'm finding a similar project in the Python world, not Scala.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
lqez
  • 2,898
  • 5
  • 25
  • 55

2 Answers2

3

OMG, I found this : https://github.com/erans/pysnowflake

lqez
  • 2,898
  • 5
  • 25
  • 55
1

You may find what you need in the Python uuid module

Rodrigue
  • 3,617
  • 2
  • 37
  • 49
  • 2
    Thank you for comment. But I don't think python uuid gives same or similar result that I want. See http://stackoverflow.com/questions/8713873/is-python-uuid1-sequential-as-timestamps – lqez Jul 25 '12 at 13:14
  • 1
    @lqez Are you aware that the current versions of Python allow you to provide a key function for ordering? If you use `uuid1()` or another function that includes the timestamp to create your UUIDs, you should be able to include `key=lambda id: id.time` or `key=operator.attrgetter('time')` in the arguments to whatever ordering system you're using and have no problem at all. And if all else fails and you're using Python 3.2, you can subclass `uuid.UUID` and use [`functools.total_ordering()`](http://docs.python.org/py3k/library/functools.html#functools.total_ordering) to set it up. – JAB Jul 25 '12 at 17:25
  • (Of course, you can still do the subclassing with earlier versions of Python, it would just take a bit more code as you'd have to define all the comparison functions manually.) – JAB Jul 25 '12 at 17:30