Skip to content

Commit ecbb1ca

Browse files
committed
renames diffsync.DiffSync to diffsync.Adapter
1 parent 8732b24 commit ecbb1ca

File tree

23 files changed

+88
-81
lines changed

23 files changed

+88
-81
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DiffSync is at its most useful when you have multiple sources or sets of data to
1515

1616
# Overview of DiffSync
1717

18-
DiffSync acts as an intermediate translation layer between all of the data sets you are diffing and/or syncing. In practical terms, this means that to use DiffSync, you will define a set of data models as well as the “adapters” needed to translate between each base data source and the data model. In Python terms, the adapters will be subclasses of the `DiffSync` class, and each data model class will be a subclass of the `DiffSyncModel` class.
18+
DiffSync acts as an intermediate translation layer between all of the data sets you are diffing and/or syncing. In practical terms, this means that to use DiffSync, you will define a set of data models as well as the “adapters” needed to translate between each base data source and the data model. In Python terms, the adapters will be subclasses of the `Adapter` class, and each data model class will be a subclass of the `DiffSyncModel` class.
1919

2020
![Diffsync Components](https://raw.githubusercontent.com/networktocode/diffsync/develop/docs/images/diffsync_components.png "Diffsync Components")
2121

diffsync/__init__.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class DiffSyncModel(BaseModel):
9696
Can be set as a class attribute or an instance attribute as needed.
9797
"""
9898

99-
diffsync: Optional["DiffSync"] = None
99+
diffsync: Optional["Adapter"] = None
100100
"""Optional: the DiffSync instance that owns this model instance."""
101101

102102
_status: DiffSyncStatus = PrivateAttr(DiffSyncStatus.SUCCESS)
@@ -183,7 +183,7 @@ def set_status(self, status: DiffSyncStatus, message: StrType = "") -> None:
183183
self._status_message = message
184184

185185
@classmethod
186-
def create_base(cls, diffsync: "DiffSync", ids: Dict, attrs: Dict) -> Optional[Self]:
186+
def create_base(cls, diffsync: "Adapter", ids: Dict, attrs: Dict) -> Optional[Self]:
187187
"""Instantiate this class, along with any platform-specific data creation.
188188
189189
This method is not meant to be subclassed, users should redefine create() instead.
@@ -201,7 +201,7 @@ def create_base(cls, diffsync: "DiffSync", ids: Dict, attrs: Dict) -> Optional[S
201201
return model
202202

203203
@classmethod
204-
def create(cls, diffsync: "DiffSync", ids: Dict, attrs: Dict) -> Optional[Self]:
204+
def create(cls, diffsync: "Adapter", ids: Dict, attrs: Dict) -> Optional[Self]:
205205
"""Instantiate this class, along with any platform-specific data creation.
206206
207207
Subclasses must call `super().create()` or `self.create_base()`; they may wish to then override the default status information
@@ -402,7 +402,7 @@ def remove_child(self, child: "DiffSyncModel") -> None:
402402
childs.remove(child.get_unique_id())
403403

404404

405-
class DiffSync: # pylint: disable=too-many-public-methods
405+
class Adapter: # pylint: disable=too-many-public-methods
406406
"""Class for storing a group of DiffSyncModel instances and diffing/synchronizing to another DiffSync instance."""
407407

408408
# In any subclass, you would add mapping of names to specific model classes here:
@@ -535,7 +535,7 @@ def load_from_dict(self, data: Dict) -> None:
535535

536536
def sync_from( # pylint: disable=too-many-arguments
537537
self,
538-
source: "DiffSync",
538+
source: "Adapter",
539539
diff_class: Type[Diff] = Diff,
540540
flags: DiffSyncFlags = DiffSyncFlags.NONE,
541541
callback: Optional[Callable[[StrType, int, int], None]] = None,
@@ -573,7 +573,7 @@ def sync_from( # pylint: disable=too-many-arguments
573573

574574
def sync_to( # pylint: disable=too-many-arguments
575575
self,
576-
target: "DiffSync",
576+
target: "Adapter",
577577
diff_class: Type[Diff] = Diff,
578578
flags: DiffSyncFlags = DiffSyncFlags.NONE,
579579
callback: Optional[Callable[[StrType, int, int], None]] = None,
@@ -597,7 +597,7 @@ def sync_to( # pylint: disable=too-many-arguments
597597

598598
def sync_complete(
599599
self,
600-
source: "DiffSync",
600+
source: "Adapter",
601601
diff: Diff,
602602
flags: DiffSyncFlags = DiffSyncFlags.NONE,
603603
logger: Optional[structlog.BoundLogger] = None,
@@ -623,7 +623,7 @@ def sync_complete(
623623

624624
def diff_from(
625625
self,
626-
source: "DiffSync",
626+
source: "Adapter",
627627
diff_class: Type[Diff] = Diff,
628628
flags: DiffSyncFlags = DiffSyncFlags.NONE,
629629
callback: Optional[Callable[[StrType, int, int], None]] = None,
@@ -644,7 +644,7 @@ def diff_from(
644644

645645
def diff_to(
646646
self,
647-
target: "DiffSync",
647+
target: "Adapter",
648648
diff_class: Type[Diff] = Diff,
649649
flags: DiffSyncFlags = DiffSyncFlags.NONE,
650650
callback: Optional[Callable[[StrType, int, int], None]] = None,
@@ -854,5 +854,8 @@ def count(self, model: Union[StrType, "DiffSyncModel", Type["DiffSyncModel"], No
854854
return self.store.count(model=model)
855855

856856

857+
# For backwards-compatibility, keep around the old name
858+
DiffSync = Adapter
859+
857860
# DiffSyncModel references DiffSync and DiffSync references DiffSyncModel. Break the typing loop:
858861
DiffSyncModel.model_rebuild()

diffsync/helpers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
if TYPE_CHECKING: # pragma: no cover
2828
# For type annotation purposes, we have a circular import loop between __init__.py and this file.
29-
from . import DiffSync, DiffSyncModel # pylint: disable=cyclic-import
29+
from . import Adapter, DiffSyncModel # pylint: disable=cyclic-import
3030

3131

3232
class DiffSyncDiffer: # pylint: disable=too-many-instance-attributes
@@ -37,8 +37,8 @@ class DiffSyncDiffer: # pylint: disable=too-many-instance-attributes
3737

3838
def __init__( # pylint: disable=too-many-arguments
3939
self,
40-
src_diffsync: "DiffSync",
41-
dst_diffsync: "DiffSync",
40+
src_diffsync: "Adapter",
41+
dst_diffsync: "Adapter",
4242
flags: DiffSyncFlags,
4343
diff_class: Type[Diff] = Diff,
4444
callback: Optional[Callable[[str, int, int], None]] = None,
@@ -288,8 +288,8 @@ class DiffSyncSyncer: # pylint: disable=too-many-instance-attributes
288288
def __init__( # pylint: disable=too-many-arguments
289289
self,
290290
diff: Diff,
291-
src_diffsync: "DiffSync",
292-
dst_diffsync: "DiffSync",
291+
src_diffsync: "Adapter",
292+
dst_diffsync: "Adapter",
293293
flags: DiffSyncFlags,
294294
callback: Optional[Callable[[str, int, int], None]] = None,
295295
):

diffsync/store/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
if TYPE_CHECKING:
88
from diffsync import DiffSyncModel
9-
from diffsync import DiffSync
9+
from diffsync import Adapter
1010

1111

1212
class BaseStore:
@@ -15,7 +15,7 @@ class BaseStore:
1515
def __init__(
1616
self, # pylint: disable=unused-argument
1717
*args: Any, # pylint: disable=unused-argument
18-
diffsync: Optional["DiffSync"] = None,
18+
diffsync: Optional["Adapter"] = None,
1919
name: str = "",
2020
**kwargs: Any, # pylint: disable=unused-argument
2121
) -> None:

docs/source/core_engine/01-flags.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ diff = nautobot.diff_from(local, flags=flags)
3434
Model flags are stored in the attribute `model_flags` of each model and are usually set when the data is being loaded into the adapter.
3535

3636
```python
37-
from diffsync import DiffSync
37+
from diffsync import Adapter
3838
from diffsync.enum import DiffSyncModelFlags
3939
from model import MyDeviceModel
4040

41-
class MyAdapter(DiffSync):
4241

42+
class MyAdapter(Adapter):
4343
device = MyDeviceModel
4444

4545
def load(self, data):

docs/source/core_engine/03-store.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,36 @@
22

33
By default, `Diffsync` supports a local memory storage. All the loaded models from the adapters will be stored in memory, and become available for the diff calculation and sync process. This default behavior works well when executing all the steps in the same process, having access to the same memory space. However, if you want to scale out the execution of the tasks, running it in different processes or in totally different workers, a more distributed memory support is necessary.
44

5-
The `store` is a class attribute in the `DiffSync` class, but all the store operations in that class are abstracted in the following methods: `get_all_model_names`, `get`, `get_by_uids`, `add`, `update`, `remove`, `get_or_instantiate`, `update_or_instantiate` and `count`.
5+
The `store` is a class attribute in the `Adapter` class, but all the store operations in that class are abstracted in the following methods: `get_all_model_names`, `get`, `get_by_uids`, `add`, `update`, `remove`, `get_or_instantiate`, `update_or_instantiate` and `count`.
66

77
## Use the `LocalStore` Backend
88

99
When you initialize the `Diffsync` Adapter class, there is an optional keyed-argument, `internal_storage_engine`, defaulting to the `LocalStore` class.
1010

1111
```python
12-
>>> from diffsync import DiffSync
13-
>>> adapter = DiffSync()
14-
>>> type(adapter.store)
15-
<class 'diffsync.store.local.LocalStore'>
12+
>> > from diffsync import Adapter
13+
>> > adapter = Adapter()
14+
>> > type(adapter.store)
15+
<
16+
17+
class 'diffsync.store.local.LocalStore'>
1618
```
1719

1820
## Use the `RedisStore` Backend
1921

2022
To get it, you have to install diffsync package with the "redis" extra option: `pip install diffsync[redis]`
2123

22-
The `RedisStore` backend, as the name suggests, connects to an external Redis service, to store data loaded by the `DiffSync` tasks. The biggest change is that it requires to initialize the Redis store class, before using it in the `DiffSync` adapter class.
24+
The `RedisStore` backend, as the name suggests, connects to an external Redis service, to store data loaded by the `Adapter` tasks. The biggest change is that it requires to initialize the Redis store class, before using it in the `Adapter` adapter class.
2325

2426
```python
25-
>>> from diffsync import DiffSync
26-
>>> from diffsync.store.redis import RedisStore
27-
>>> store = RedisStore(host="redis host")
28-
>>> adapter = DiffSync(internal_storage_engine=store)
29-
>>> type(adapter.store)
30-
<class 'diffsync.store.local.RedisStore'>
27+
>> > from diffsync import Adapter
28+
>> > from diffsync.store.redis import RedisStore
29+
>> > store = RedisStore(host="redis host")
30+
>> > adapter = Adapter(internal_storage_engine=store)
31+
>> > type(adapter.store)
32+
<
33+
34+
class 'diffsync.store.local.RedisStore'>
3135
```
3236

3337
Notice that the `RedisStore` will validate, when initialized, that there is a reachability to the Redis host, and if not, will raise an exception:

docs/source/getting_started/01-getting-started.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
To be able to properly compare different datasets, DiffSync relies on a shared data model that both systems must use.
2-
Specifically, each system or dataset must provide a `DiffSync` "adapter" subclass, which in turn represents its dataset as instances of one or more `DiffSyncModel` data model classes.
2+
Specifically, each system or dataset must provide a `Adapter` "adapter" subclass, which in turn represents its dataset as instances of one or more `DiffSyncModel` data model classes.
33

44
When comparing two systems, DiffSync detects the intersection between the two systems (which data models they have in common, and which attributes are shared between each pair of data models) and uses this intersection to compare and/or synchronize the data.
55

@@ -41,24 +41,24 @@ Currently the relationships between models are very loose by design. Instead of
4141

4242
# Define your system adapter with DiffSync
4343

44-
A `DiffSync` "adapter" subclass must reference each model available at the top of the object by its modelname and must have a `top_level` attribute defined to indicate how the diff and the synchronization should be done. In the example below, `"site"` is the only top level object so the synchronization engine will only check all known `Site` instances and all children of each Site. In this case, as shown in the code above, `Device`s are children of `Site`s, so this is exactly the intended logic.
44+
A `Adapter` "adapter" subclass must reference each model available at the top of the object by its modelname and must have a `top_level` attribute defined to indicate how the diff and the synchronization should be done. In the example below, `"site"` is the only top level object so the synchronization engine will only check all known `Site` instances and all children of each Site. In this case, as shown in the code above, `Device`s are children of `Site`s, so this is exactly the intended logic.
4545

4646
```python
47-
from diffsync import DiffSync
47+
from diffsync import Adapter
4848

49-
class BackendA(DiffSync):
5049

50+
class BackendA(Adapter):
5151
site = Site
5252
device = Device
5353

5454
top_level = ["site"]
5555
```
5656

57-
It's up to the implementer to populate the `DiffSync`'s internal cache with the appropriate data. In the example below we are using the `load()` method to populate the cache but it's not mandatory, it could be done differently.
57+
It's up to the implementer to populate the `Adapter`'s internal cache with the appropriate data. In the example below we are using the `load()` method to populate the cache but it's not mandatory, it could be done differently.
5858

5959
## Model Processing Ordering Logic
6060

61-
The models will be processed in a specfic order as defined by `top_level` atttribute on the `DiffSync` object and then the `_children` attribute on the `DiffSyncModel`. The processing algorithm is technically a "Preorder Tree Traversal", which means that "a parent node is processed before any of its child nodes is done." This can be described as:
61+
The models will be processed in a specfic order as defined by `top_level` atttribute on the `Adapter` object and then the `_children` attribute on the `DiffSyncModel`. The processing algorithm is technically a "Preorder Tree Traversal", which means that "a parent node is processed before any of its child nodes is done." This can be described as:
6262

6363
- Start with the first element of the first model in `top_level` and process it.
6464
- If that model has `_children` set on it, for each child of each child model, in order:
@@ -145,7 +145,7 @@ NetworkImporterAdapter
145145
>>>
146146
```
147147

148-
# Store data in a `DiffSync` object
148+
# Store data in a `Adapter` object
149149

150150
To add a site to the local cache/store, you need to pass a valid `DiffSyncModel` object to the `add()` function.
151151

@@ -174,7 +174,7 @@ convenient to manage individual records (as in a database) or modify the entire
174174
## Manage individual records
175175

176176
To update individual records in a remote system, you need to extend your `DiffSyncModel` class(es) to define your own `create`, `update` and/or `delete` methods for each model.
177-
A `DiffSyncModel` instance stores a reference to its parent `DiffSync` adapter instance in case you need to use it to look up other model instances from the `DiffSync`'s cache.
177+
A `DiffSyncModel` instance stores a reference to its parent `Adapter` adapter instance in case you need to use it to look up other model instances from the `Adapter`'s cache.
178178

179179
```python
180180
class Device(DiffSyncModel):

examples/01-multiple-data-sources/backend_a.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717

1818
# pylint: disable=wrong-import-order
19-
from diffsync import DiffSync
19+
from diffsync import Adapter
2020
from models import Site, Device, Interface # pylint: disable=no-name-in-module
2121

2222
DATA = {
@@ -31,7 +31,7 @@
3131
}
3232

3333

34-
class BackendA(DiffSync):
34+
class BackendA(Adapter):
3535
"""Example of a DiffSync adapter implementation."""
3636

3737
site = Site

examples/01-multiple-data-sources/backend_b.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717

1818
# pylint: disable=wrong-import-order
19-
from diffsync import DiffSync
19+
from diffsync import Adapter
2020
from models import Site, Device, Interface # pylint: disable=no-name-in-module
2121

2222
DATA = {
@@ -35,7 +35,7 @@
3535
}
3636

3737

38-
class BackendB(DiffSync):
38+
class BackendB(Adapter):
3939
"""Example of a DiffSync adapter implementation."""
4040

4141
site = Site

examples/01-multiple-data-sources/backend_c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717

1818
# pylint: disable=wrong-import-order
19-
from diffsync import DiffSync
19+
from diffsync import Adapter
2020
from models import Site, Device, Interface # pylint: disable=no-name-in-module
2121

2222
DATA = {
@@ -31,7 +31,7 @@
3131
}
3232

3333

34-
class BackendC(DiffSync):
34+
class BackendC(Adapter):
3535
"""Example of a DiffSync adapter implementation."""
3636

3737
site = Site

0 commit comments

Comments
 (0)