diff --git a/.gitignore b/.gitignore index 8ab99c0..0f1f276 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +.DS_Store # PyInstaller # Usually these files are written by a python script from a template diff --git a/README.md b/README.md index ebc1bd2..db21540 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,12 @@ pip install snowfall ``` ### Quickstart -To start generating IDs, simply instantiate a `Snowfall`. +To start generating IDs, simply create a schema group and start a `Snowfall`. ``` from snowfall import Snowfall +from snowfall.generator_syncers import SimpleSyncer +SimpleSyncer.create_schema_group() id_generator = Snowfall() ``` Successively calling `get_guid()` will return valid GUIDs. @@ -49,10 +51,11 @@ The `generator_syncers` module contains classes that enforce this constraint by #### For single-process projects For single-process projects, we provide a `SimpleSyncer` that records the manifest as a Python data structure. First, create a new global schema group, and then bind the Snowfall instance to it. + +All `Snowfall` instances that share the same schema group will not create duplicate GUIDs. ``` -from datetime import datetime from snowfall import Snowfall -from snowfall.generator_syncers.simple_syncer import SimpleSyncer +from snowfall.generator_syncers import SimpleSyncer SimpleSyncer.create_schema_group( schema_group_name="example_schema_group" @@ -84,7 +87,7 @@ For multi-process, multi-container projects, we need to persist the `generator_i ``` from datetime import datetime from snowfall import Snowfall -from snowfall.generator_syncers.database_syncer import DatabaseSyncer +from snowfall.generator_syncers import DatabaseSyncer DatabaseSyncer.create_schema_group( schema_group_name="example_schema_group" diff --git a/snowfall/__init__.py b/snowfall/__init__.py new file mode 100644 index 0000000..af895d1 --- /dev/null +++ b/snowfall/__init__.py @@ -0,0 +1 @@ +from snowfall.main import Snowfall diff --git a/snowfall/generator_syncers/__init__.py b/snowfall/generator_syncers/__init__.py new file mode 100644 index 0000000..2d72262 --- /dev/null +++ b/snowfall/generator_syncers/__init__.py @@ -0,0 +1,3 @@ +from snowfall.generator_syncers.abstracts import BaseSyncer +from snowfall.generator_syncers.database_syncer import DatabaseSyncer +from snowfall.generator_syncers.simple_syncer import SimpleSyncer diff --git a/src/generator_syncers/abstracts.py b/snowfall/generator_syncers/abstracts.py similarity index 97% rename from src/generator_syncers/abstracts.py rename to snowfall/generator_syncers/abstracts.py index 2deb02d..324548a 100644 --- a/src/generator_syncers/abstracts.py +++ b/snowfall/generator_syncers/abstracts.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from apscheduler.schedulers.background import BackgroundScheduler -from utils import get_current_timestamp_ms +from snowfall.utils import get_current_timestamp_ms class BaseSyncer(ABC): diff --git a/src/generator_syncers/database_syncer.py b/snowfall/generator_syncers/database_syncer.py similarity index 98% rename from src/generator_syncers/database_syncer.py rename to snowfall/generator_syncers/database_syncer.py index 33d02d5..b4adfb9 100644 --- a/src/generator_syncers/database_syncer.py +++ b/snowfall/generator_syncers/database_syncer.py @@ -9,8 +9,8 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.engine.base import Engine -from generator_syncers.abstracts import BaseSyncer -from utils import get_current_timestamp_ms +from snowfall.generator_syncers.abstracts import BaseSyncer +from snowfall.utils import get_current_timestamp_ms class DatabaseSyncer(BaseSyncer): diff --git a/src/generator_syncers/simple_syncer.py b/snowfall/generator_syncers/simple_syncer.py similarity index 97% rename from src/generator_syncers/simple_syncer.py rename to snowfall/generator_syncers/simple_syncer.py index afbbdec..5e56872 100644 --- a/src/generator_syncers/simple_syncer.py +++ b/snowfall/generator_syncers/simple_syncer.py @@ -2,8 +2,8 @@ from collections import namedtuple import numpy as np -from generator_syncers.abstracts import BaseSyncer -from utils import get_current_timestamp_ms +from snowfall.generator_syncers.abstracts import BaseSyncer +from snowfall.utils import get_current_timestamp_ms SchemaGroup = namedtuple( diff --git a/src/main.py b/snowfall/main.py similarity index 96% rename from src/main.py rename to snowfall/main.py index 25b4e66..7c2df1f 100644 --- a/src/main.py +++ b/snowfall/main.py @@ -2,8 +2,8 @@ from datetime import datetime from time import sleep -from generator_syncers import BaseSyncer, SimpleSyncer -from utils import get_current_timestamp_ms +from snowfall.generator_syncers import BaseSyncer, SimpleSyncer +from snowfall.utils import get_current_timestamp_ms class Snowfall: diff --git a/src/utils.py b/snowfall/utils.py similarity index 100% rename from src/utils.py rename to snowfall/utils.py diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index dd160f5..0000000 --- a/src/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from main import Snowfall diff --git a/src/generator_syncers/__init__.py b/src/generator_syncers/__init__.py deleted file mode 100644 index af7f4bb..0000000 --- a/src/generator_syncers/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from generator_syncers.abstracts import BaseSyncer -from generator_syncers.database_syncer import DatabaseSyncer -from generator_syncers.simple_syncer import SimpleSyncer