Stores
Note
Some Store
classes require extra packages that are not installed by default. Run the following modified installation commands if you want to use these stores:
MongograntStore
:
pip install maggma[mongogrant]
MontyStore
:
pip install maggma[montydb]
VaultStore
:
pip install maggma[vault]
Module containing various definitions of Stores. Stores are a default access pattern to data and provide various utilities.
JSONStore
¶
Bases: MemoryStore
A Store for access to a single or multiple JSON files.
Source code in src/maggma/stores/mongolike.py
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 |
|
__eq__(other)
¶
Check equality for JSONStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
other JSONStore to compare with |
required |
Source code in src/maggma/stores/mongolike.py
776 777 778 779 780 781 782 783 784 785 786 787 |
|
__init__(paths, read_only=True, serialization_option=None, serialization_default=None, encoding=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths |
Union[str, list[str]]
|
paths for json files to turn into a Store |
required |
read_only |
bool
|
whether this JSONStore is read only. When read_only=True, the JSONStore can still apply MongoDB-like writable operations (e.g. an update) because it behaves like a MemoryStore, but it will not write those changes to the file. On the other hand, if read_only=False (i.e., it is writeable), the JSON file will be automatically updated every time a write-like operation is performed.
|
True
|
serialization_option |
Optional[int]
|
option that will be passed to the orjson.dump when saving to the json the file. |
None
|
serialization_default |
Optional[Callable[[Any], Any]]
|
default that will be passed to the orjson.dump when saving to the json the file. |
None
|
encoding |
Optional[str]
|
Character encoding of files to be tracked by the store. The default (None) follows python's default behavior, which is to determine the character encoding from the platform. This should work in the great majority of cases. However, if you encounter a UnicodeDecodeError, consider setting the encoding explicitly to 'utf8' or another encoding as appropriate. |
None
|
Source code in src/maggma/stores/mongolike.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
|
connect(force_reset=False)
¶
Loads the files into the collection in memory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not. If False (default) and .connect() |
False
|
Source code in src/maggma/stores/mongolike.py
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
read_json_file(path)
¶
Helper method to read the contents of a JSON file and generate a list of docs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path to the JSON file to be read |
required |
Source code in src/maggma/stores/mongolike.py
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
|
remove_docs(criteria)
¶
Remove docs matching the query dictionary.
For a file-writable JSONStore, the json file is updated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
Source code in src/maggma/stores/mongolike.py
745 746 747 748 749 750 751 752 753 754 755 756 |
|
update(docs, key=None)
¶
Update documents into the Store.
For a file-writable JSONStore, the json file is updated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
Source code in src/maggma/stores/mongolike.py
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 |
|
update_json_file()
¶
Updates the json file when a write-like operation is performed.
Source code in src/maggma/stores/mongolike.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
|
MemoryStore
¶
Bases: MongoStore
An in-memory Store that functions similarly to a MongoStore.
Source code in src/maggma/stores/mongolike.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
|
name
property
¶
Name for the store.
__eq__(other)
¶
Check equality for MemoryStore other: other MemoryStore to compare with.
Source code in src/maggma/stores/mongolike.py
590 591 592 593 594 595 596 597 598 599 |
|
__hash__()
¶
Hash for the store.
Source code in src/maggma/stores/mongolike.py
541 542 543 |
|
__init__(collection_name='memory_db', **kwargs)
¶
Initializes the Memory Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
name for the collection in memory. |
'memory_db'
|
Source code in src/maggma/stores/mongolike.py
508 509 510 511 512 513 514 515 516 517 518 519 |
|
close()
¶
Close up all collections.
Source code in src/maggma/stores/mongolike.py
532 533 534 |
|
connect(force_reset=False)
¶
Connect to the source data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/mongolike.py
521 522 523 524 525 526 527 528 529 530 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (key, list of elements) |
Source code in src/maggma/stores/mongolike.py
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
|
MongoStore
¶
Bases: Store
A Store that connects to a Mongo collection.
Source code in src/maggma/stores/mongolike.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
|
name: str
property
¶
Return a string representing this data source.
__eq__(other)
¶
Check equality for MongoStore other: other mongostore to compare with.
Source code in src/maggma/stores/mongolike.py
424 425 426 427 428 429 430 431 432 433 |
|
__hash__()
¶
Hash for MongoStore.
Source code in src/maggma/stores/mongolike.py
125 126 127 |
|
__init__(database, collection_name, host='localhost', port=27017, username='', password='', ssh_tunnel=None, safe_update=False, auth_source=None, mongoclient_kwargs=None, default_sort=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database |
str
|
The database name |
required |
collection_name |
str
|
The collection name |
required |
host |
str
|
Hostname for the database |
'localhost'
|
port |
int
|
TCP port to connect to |
27017
|
username |
str
|
Username for the collection |
''
|
password |
str
|
Password to connect with |
''
|
safe_update |
bool
|
fail gracefully on DocumentTooLarge errors on update |
False
|
auth_source |
Optional[str]
|
The database to authenticate on. Defaults to the database name. |
None
|
default_sort |
Optional[dict[str, Union[Sort, int]]]
|
Default sort field and direction to use when querying. Can be used to ensure determinacy in query results. |
None
|
Source code in src/maggma/stores/mongolike.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
close()
¶
Close up all collections.
Source code in src/maggma/stores/mongolike.py
417 418 419 420 421 422 |
|
connect(force_reset=False)
¶
Connect to the source data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/mongolike.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
count(criteria=None, hint=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
hint |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of indexes to use as hints for query optimizer. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
Source code in src/maggma/stores/mongolike.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
distinct(field, criteria=None, all_exist=False)
¶
Get all distinct values for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
the field(s) to get distinct values for |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
Source code in src/maggma/stores/mongolike.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
ensure_index(key, unique=False)
¶
Tries to create an index and return true if it succeeded.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
single key to index |
required |
unique |
Optional[bool]
|
Whether or not this index contains only unique keys. |
False
|
Returns:
Type | Description |
---|---|
bool
|
bool indicating if the index exists/was created |
Source code in src/maggma/stores/mongolike.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
from_collection(collection)
classmethod
¶
Generates a MongoStore from a pymongo collection object This is not a fully safe operation as it gives dummy information to the MongoStore As a result, this will not serialize and can not reset its connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection |
the PyMongo collection to create a MongoStore around |
required |
Source code in src/maggma/stores/mongolike.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
from_db_file(filename, **kwargs)
classmethod
¶
Convenience method to construct MongoStore from db_file from old QueryEngine format.
Source code in src/maggma/stores/mongolike.py
129 130 131 132 133 134 135 136 137 138 139 140 |
|
from_launchpad_file(lp_file, collection_name, **kwargs)
classmethod
¶
Convenience method to construct MongoStore from a launchpad file.
Note: A launchpad file is a special formatted yaml file used in fireworks
Returns:
Source code in src/maggma/stores/mongolike.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (key, list of docs) |
Source code in src/maggma/stores/mongolike.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
query(criteria=None, properties=None, sort=None, hint=None, skip=0, limit=0, **kwargs)
¶
Queries the Store for a set of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
hint |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of indexes to use as hints for query optimizer. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
mongoclient_kwargs |
Dict of extra kwargs to pass to pymongo find. |
required |
Source code in src/maggma/stores/mongolike.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
remove_docs(criteria)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
Source code in src/maggma/stores/mongolike.py
408 409 410 411 412 413 414 415 |
|
update(docs, key=None)
¶
Update documents into the Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
Source code in src/maggma/stores/mongolike.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
MongoURIStore
¶
Bases: MongoStore
A Store that connects to a Mongo collection via a URI This is expected to be a special mongodb+srv:// URIs that include client parameters via TXT records.
Source code in src/maggma/stores/mongolike.py
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
name: str
property
¶
Return a string representing this data source.
__init__(uri, collection_name, database=None, ssh_tunnel=None, mongoclient_kwargs=None, default_sort=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
str
|
MongoDB+SRV URI |
required |
database |
Optional[str]
|
database to connect to |
None
|
collection_name |
str
|
The collection name |
required |
default_sort |
Optional[dict[str, Union[Sort, int]]]
|
Default sort field and direction to use when querying. Can be used to ensure determinacy in query results. |
None
|
Source code in src/maggma/stores/mongolike.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
|
connect(force_reset=False)
¶
Connect to the source data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/mongolike.py
488 489 490 491 492 493 494 495 496 497 498 499 |
|
MontyStore
¶
Bases: MemoryStore
A MongoDB compatible store that uses on disk files for storage.
This is handled under the hood using MontyDB. A number of on-disk storage options are available but MontyDB provides a mongo style interface for all options. The options include:
- sqlite: Uses an sqlite database to store documents.
- lightning: Uses Lightning Memory-Mapped Database (LMDB) for storage. This can
provide fast read and write times but requires lmdb to be installed (in most cases
this can be achieved using
pip install lmdb
). - flatfile: Uses a system of flat json files. This is not recommended as multiple simultaneous connections to the store will not work correctly.
Note that MontyDB (and, therefore, MontyStore) will write out a new database to the disk but cannot be used to read an existing (e.g. SQLite) database that wasn't formatted by MontyDB.
See the MontyDB repository for more information: https://github.com/davidlatwe/montydb
Source code in src/maggma/stores/mongolike.py
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
|
name: str
property
¶
Return a string representing this data source.
__init__(collection_name, database_path=None, database_name='db', storage='sqlite', storage_kwargs=None, client_kwargs=None, **kwargs)
¶
Initializes the Monty Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
Name for the collection. |
required | |
database_path |
Optional[str]
|
Path to on-disk database files. If None, the current working directory will be used. |
None
|
database_name |
str
|
The database name. |
'db'
|
storage |
Literal['sqlite', 'flatfile', 'lightning']
|
The storage type. Options include "sqlite", "lightning", "flatfile". Note that |
'sqlite'
|
storage_kwargs |
Optional[dict]
|
Keyword arguments passed to |
None
|
client_kwargs |
Optional[dict]
|
Keyword arguments passed to the |
None
|
**kwargs |
Additional keyword arguments passed to the Store constructor. |
{}
|
Source code in src/maggma/stores/mongolike.py
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 |
|
connect(force_reset=False)
¶
Connect to the database store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/mongolike.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 |
|
count(criteria=None, hint=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
hint |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of indexes to use as hints for query optimizer. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
Source code in src/maggma/stores/mongolike.py
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
|
update(docs, key=None)
¶
Update documents into the Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
The document or list of documents to update. |
required |
key |
Union[list, str, None]
|
Field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used. |
None
|
Source code in src/maggma/stores/mongolike.py
905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 |
|
Module defining a FileStore that enables accessing files in a local directory using typical maggma access patterns.
FileStore
¶
Bases: MemoryStore
A Store for files on disk. Provides a common access method consistent with other stores. Each Item in the Store represents one file. Files can be organized into any type of directory structure.
A hash of the full path to each file is used to define a file_id that uniquely identifies each item.
Any metadata added to the items is written to a .json file in the root directory of the FileStore.
Source code in src/maggma/stores/file_store.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
name: str
property
¶
Return a string representing this data source.
__init__(path, file_filters=None, max_depth=None, read_only=True, include_orphans=False, json_name='FileStore.json', encoding=None, **kwargs)
¶
Initializes a FileStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
parent directory containing all files and subdirectories to process |
required |
file_filters |
Optional[list]
|
List of fnmatch patterns defining the files to be tracked by the FileStore. Only files that match one of the patterns provided will be included in the Store If None (default), all files are included. Examples: ["*.txt", "test-[abcd].txt"], etc. See https://docs.python.org/3/library/fnmatch.html for full syntax |
None
|
max_depth |
Optional[int]
|
The maximum depth to look into subdirectories. 0 = no recursion, 1 = include files 1 directory below the FileStore, etc. None (default) will scan all files below the FileStore root directory, regardless of depth. |
None
|
read_only |
bool
|
If True (default), the .update() and .remove_docs() methods are disabled, preventing any changes to the files on disk. In addition, metadata cannot be written to disk. |
True
|
include_orphans |
bool
|
Whether to include orphaned metadata records in query results. Orphaned metadata records are records found in the local JSON file that can no longer be associated to a file on disk. This can happen if a file is renamed or deleted, or if the FileStore is re-initialized with a more restrictive file_filters or max_depth argument. By default (False), these records do not appear in query results. Nevertheless, the metadata records are retained in the JSON file and the FileStore to prevent accidental data loss. |
False
|
json_name |
str
|
Name of the .json file to which metadata is saved. If read_only is False, this file will be created in the root directory of the FileStore. |
'FileStore.json'
|
encoding |
Optional[str]
|
Character encoding of files to be tracked by the store. The default (None) follows python's default behavior, which is to determine the character encoding from the platform. This should work in the great majority of cases. However, if you encounter a UnicodeDecodeError, consider setting the encoding explicitly to 'utf8' or another encoding as appropriate. |
None
|
kwargs |
kwargs passed to MemoryStore.init() |
{}
|
Source code in src/maggma/stores/file_store.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
add_metadata(metadata=None, query=None, auto_data=None, **kwargs)
¶
Add metadata to a record in the FileStore, either manually or by computing it automatically from another field, such as name or path (see auto_data).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
Optional[dict]
|
dict of additional data to add to the records returned by query. Note that any protected keys (such as 'name', 'path', etc.) will be ignored. |
None
|
query |
Optional[dict]
|
Query passed to FileStore.query() |
None
|
auto_data |
Optional[Callable[[dict], dict]]
|
A function that automatically computes metadata based on a field in
the record itself. The function must take in the item as a dict and
return a dict containing the desired metadata. A typical use case is
to assign metadata based on the name of a file. For example, for
data files named like
|
None
|
kwargs |
kwargs passed to FileStore.query() |
{}
|
Source code in src/maggma/stores/file_store.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
connect(force_reset=False)
¶
Connect to the source data.
Read all the files in the directory, create corresponding File items in the internal MemoryStore.
If there is a metadata .json file in the directory, read its contents into the MemoryStore
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/file_store.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
query(criteria=None, properties=None, sort=None, hint=None, skip=0, limit=0, contents_size_limit=0)
¶
Queries the Store for a set of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
hint |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of indexes to use as hints for query optimizer. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
contents_size_limit |
Optional[int]
|
Maximum file size in bytes for which to return contents. The FileStore will attempt to read the file and populate the 'contents' key with its content at query time, unless the file size is larger than this value. By default, reading content is disabled. Note that enabling content reading can substantially slow down the query operation, especially when there are large numbers of files. |
0
|
Source code in src/maggma/stores/file_store.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
query_one(criteria=None, properties=None, sort=None, contents_size_limit=None)
¶
Queries the Store for a single document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search |
None
|
properties |
Union[dict, list, None]
|
properties to return in the document |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
contents_size_limit |
Optional[int]
|
Maximum file size in bytes for which to return contents. The FileStore will attempt to read the file and populate the 'contents' key with its content at query time, unless the file size is larger than this value. |
None
|
Source code in src/maggma/stores/file_store.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
|
read()
¶
Iterate through all files in the Store folder and populate the Store with dictionaries containing basic information about each file.
The keys of the documents added to the Store are:
- name: str = File name
- path: Path = Absolute path of this file
- parent: str = Name of the parent directory (if any)
- file_id: str = Unique identifier for this file, computed from the hash
of its path relative to the base FileStore directory and
the file creation time. The key of this field is 'file_id'
by default but can be changed via the 'key' kwarg to
FileStore.__init__()
. - size: int = Size of this file in bytes
- last_updated: datetime = Time this file was last modified
- hash: str = Hash of the file contents
- orphan: bool = Whether this record is an orphan
Source code in src/maggma/stores/file_store.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
remove_docs(criteria, confirm=False)
¶
Remove items matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
confirm |
bool
|
Boolean flag to confirm that remove_docs should delete files on disk. Default: False. |
False
|
Source code in src/maggma/stores/file_store.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
update(docs, key=None)
¶
Update items in the Store. Only possible if the store is not read only. Any new fields that are added will be written to the JSON file in the root directory of the FileStore.
Note that certain fields that come from file metadata on disk are protected and cannot be updated with this method. This prevents the contents of the FileStore from becoming out of sync with the files on which it is based. The protected fields are keys in the dict returned by _create_record_from_file, e.g. 'name', 'parent', 'path', 'last_updated', 'hash', 'size', 'contents', and 'orphan'. The 'path_relative' and key fields are retained to make each document in the JSON file identifiable by manual inspection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
Source code in src/maggma/stores/file_store.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
Module containing various definitions of Stores. Stores are a default access pattern to data and provide various utilities.
GridFSStore
¶
Bases: Store
A Store for GridFS backend. Provides a common access method consistent with other stores.
Source code in src/maggma/stores/gridfs.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
last_updated: datetime
property
¶
Provides the most recent last_updated date time stamp from the documents in this Store.
name: str
property
¶
Return a string representing this data source.
__eq__(other)
¶
Check equality for GridFSStore other: other GridFSStore to compare with.
Source code in src/maggma/stores/gridfs.py
422 423 424 425 426 427 428 429 430 431 |
|
__init__(database, collection_name, host='localhost', port=27017, username='', password='', compression=False, ensure_metadata=False, searchable_fields=None, auth_source=None, mongoclient_kwargs=None, ssh_tunnel=None, **kwargs)
¶
Initializes a GridFS Store for binary data Args: database: database name collection_name: The name of the collection. This is the string portion before the GridFS extensions host: hostname for the database port: port to connect to username: username to connect as password: password to authenticate as compression: compress the data as it goes into GridFS ensure_metadata: ensure returned documents have the metadata fields searchable_fields: fields to keep in the index store auth_source: The database to authenticate on. Defaults to the database name. ssh_tunnel: An SSHTunnel object to use.
Source code in src/maggma/stores/gridfs.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
connect(force_reset=False)
¶
Connect to the source data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/gridfs.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
count(criteria=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
Source code in src/maggma/stores/gridfs.py
197 198 199 200 201 202 203 204 205 206 207 |
|
distinct(field, criteria=None, all_exist=False)
¶
Get all distinct values for a field. This function only operates on the metadata in the files collection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
the field(s) to get distinct values for |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
Source code in src/maggma/stores/gridfs.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
ensure_index(key, unique=False)
¶
Tries to create an index and return true if it succeeded Currently operators on the GridFS files collection Args: key: single key to index unique: Whether or not this index contains only unique keys.
Returns:
Type | Description |
---|---|
bool
|
bool indicating if the index exists/was created |
Source code in src/maggma/stores/gridfs.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
from_launchpad_file(lp_file, collection_name, **kwargs)
classmethod
¶
Convenience method to construct a GridFSStore from a launchpad file.
Note: A launchpad file is a special formatted yaml file used in fireworks
Returns:
Source code in src/maggma/stores/gridfs.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys. Will only work if the keys are included in the files collection for GridFS.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (dict, list of docs) |
Source code in src/maggma/stores/gridfs.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
query(criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Queries the GridFS Store for a set of documents. Will check to see if data can be returned from files store first. If the data from the gridfs is not a json serialized string a dict will be returned with the data in the "data" key plus the self.key and self.last_updated_field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Source code in src/maggma/stores/gridfs.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
remove_docs(criteria)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
Source code in src/maggma/stores/gridfs.py
402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
transform_criteria(criteria)
classmethod
¶
Allow client to not need to prepend 'metadata.' to query fields.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
Query criteria |
required |
Source code in src/maggma/stores/gridfs.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
update(docs, key=None, additional_metadata=None)
¶
Update documents into the Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
additional_metadata |
Union[str, list[str], None]
|
field(s) to include in the gridfs metadata |
None
|
Source code in src/maggma/stores/gridfs.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
|
GridFSURIStore
¶
Bases: GridFSStore
A Store for GridFS backend, with connection via a mongo URI string.
This is expected to be a special mongodb+srv:// URIs that include client parameters via TXT records
Source code in src/maggma/stores/gridfs.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
__init__(uri, collection_name, database=None, compression=False, ensure_metadata=False, searchable_fields=None, mongoclient_kwargs=None, **kwargs)
¶
Initializes a GridFS Store for binary data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri |
str
|
MongoDB+SRV URI |
required |
database |
Optional[str]
|
database to connect to |
None
|
collection_name |
str
|
The collection name |
required |
compression |
bool
|
compress the data as it goes into GridFS |
False
|
ensure_metadata |
bool
|
ensure returned documents have the metadata fields |
False
|
searchable_fields |
Optional[list[str]]
|
fields to keep in the index store. |
None
|
Source code in src/maggma/stores/gridfs.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
connect(force_reset=False)
¶
Connect to the source data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/gridfs.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
Stores for connecting to AWS data.
S3Store
¶
Bases: Store
GridFS like storage using Amazon S3 and a regular store for indexing.
Assumes Amazon AWS key and secret key are set in environment or default config file.
Source code in src/maggma/stores/aws.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
|
name: str
property
¶
String representing this data source.
__eq__(other)
¶
Check equality for S3Store.
other: other S3Store to compare with.
Source code in src/maggma/stores/aws.py
573 574 575 576 577 578 579 580 581 582 583 |
|
__init__(index, bucket, s3_profile=None, compress=False, endpoint_url=None, sub_dir=None, s3_workers=1, s3_resource_kwargs=None, ssh_tunnel=None, key='fs_id', store_hash=True, unpack_data=True, searchable_fields=None, index_store_kwargs=None, **kwargs)
¶
Initializes an S3 Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
Store
|
a store to use to index the S3 bucket. |
required |
bucket |
str
|
name of the bucket. |
required |
s3_profile |
Optional[Union[str, dict]]
|
name of AWS profile containing the credentials. Alternatively you can pass in a dictionary with the full credentials: aws_access_key_id (string) -- AWS access key ID aws_secret_access_key (string) -- AWS secret access key aws_session_token (string) -- AWS temporary session token region_name (string) -- Default region when creating new connections |
None
|
compress |
bool
|
compress files inserted into the store. |
False
|
endpoint_url |
Optional[str]
|
this allows the interface with minio service; ignored if
|
None
|
sub_dir |
Optional[str]
|
subdirectory of the S3 bucket to store the data. |
None
|
s3_workers |
int
|
number of concurrent S3 puts to run. |
1
|
s3_resource_kwargs |
Optional[dict]
|
additional kwargs to pass to the boto3 session resource. |
None
|
ssh_tunnel |
Optional[SSHTunnel]
|
optional SSH tunnel to use for the S3 connection. |
None
|
key |
str
|
main key to index on. |
'fs_id'
|
store_hash |
bool
|
store the SHA1 hash right before insertion to the database. |
True
|
unpack_data |
bool
|
whether to decompress and unpack byte data when querying from the bucket. |
True
|
searchable_fields |
Optional[list[str]]
|
fields to keep in the index store. |
None
|
index_store_kwargs |
Optional[dict]
|
kwargs to pass to the index store. Allows the user to use kwargs here to update the index store. |
None
|
Source code in src/maggma/stores/aws.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
close()
¶
Closes any connections.
Source code in src/maggma/stores/aws.py
133 134 135 136 137 138 139 140 141 142 |
|
connect(force_reset=False)
¶
Connect to the source data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to force a reset of the connection |
False
|
Source code in src/maggma/stores/aws.py
123 124 125 126 127 128 129 130 131 |
|
count(criteria=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in. |
None
|
Source code in src/maggma/stores/aws.py
155 156 157 158 159 160 161 162 |
|
distinct(field, criteria=None, all_exist=False)
¶
Get all distinct values for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
the field(s) to get distinct values for. |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in. |
None
|
Source code in src/maggma/stores/aws.py
245 246 247 248 249 250 251 252 253 254 |
|
ensure_index(key, unique=False)
¶
Tries to create an index and return true if it succeeded.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
single key to index. |
required |
unique |
bool
|
whether this index contains only unique keys. |
False
|
Returns:
Type | Description |
---|---|
bool
|
bool indicating if the index exists/was created. |
Source code in src/maggma/stores/aws.py
289 290 291 292 293 294 295 296 297 298 299 300 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents. |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in. |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents. |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values |
None
|
skip |
int
|
number documents to skip. |
0
|
limit |
int
|
limit on total number of documents returned. |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (dict, list of docs) |
Source code in src/maggma/stores/aws.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
newer_in(target, criteria=None, exhaustive=False)
¶
Returns the keys of documents that are newer in the target Store than this Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Store
|
target Store. |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in. |
None
|
exhaustive |
bool
|
triggers an item-by-item check vs. checking the last_updated of the target Store and using that to filter out new items in. |
False
|
Source code in src/maggma/stores/aws.py
513 514 515 516 517 518 519 520 521 522 523 524 525 |
|
query(criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Queries the Store for a set of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in. |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents. |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip. |
0
|
limit |
int
|
limit on total number of documents returned. |
0
|
Source code in src/maggma/stores/aws.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
rebuild_index_from_s3_data(**kwargs)
¶
Rebuilds the index Store from the data in S3.
Relies on the index document being stores as the metadata for the file. This can help recover lost databases.
Source code in src/maggma/stores/aws.py
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|
rebuild_metadata_from_index(index_query=None)
¶
Read data from the index store and populate the metadata of the S3 bucket. Force all the keys to be lower case to be Minio compatible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index_query |
Optional[dict]
|
query on the index store. |
None
|
Source code in src/maggma/stores/aws.py
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
|
remove_docs(criteria, remove_s3_object=False)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match. |
required |
remove_s3_object |
bool
|
whether to remove the actual S3 object or not. |
False
|
Source code in src/maggma/stores/aws.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
|
update(docs, key=None, additional_metadata=None)
¶
Update documents into the Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update. |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used. |
None
|
additional_metadata |
Union[str, list[str], None]
|
field(s) to include in the S3 store's metadata. |
None
|
Source code in src/maggma/stores/aws.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
write_doc_to_s3(doc, search_keys)
¶
Write the data to s3 and return the metadata to be inserted into the index db.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc |
dict
|
the document. |
required |
search_keys |
list[str]
|
list of keys to pull from the docs and be inserted into the index db. |
required |
Returns:
Name | Type | Description |
---|---|---|
Dict |
dict
|
The metadata to be inserted into the index db |
Source code in src/maggma/stores/aws.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
Advanced Stores for connecting to Microsoft Azure data.
AzureBlobStore
¶
Bases: Store
GridFS like storage using Azure Blob and a regular store for indexing.
Requires azure-storage-blob and azure-identity modules to be installed.
Source code in src/maggma/stores/azure.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
|
name: str
property
¶
Returns:
Type | Description |
---|---|
str
|
a string representing this data source. |
__eq__(other)
¶
Check equality for AzureBlobStore other: other AzureBlobStore to compare with.
Source code in src/maggma/stores/azure.py
542 543 544 545 546 547 548 549 550 551 |
|
__init__(index, container_name, azure_client_info=None, compress=False, sub_dir=None, workers=1, azure_resource_kwargs=None, key='fs_id', store_hash=True, unpack_data=True, searchable_fields=None, key_sanitize_dict=None, create_container=False, **kwargs)
¶
Initializes an AzureBlob Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
Store
|
a store to use to index the Azure blob |
required |
container_name |
str
|
name of the container |
required |
azure_client_info |
Optional[Union[str, dict]]
|
connection_url of the BlobServiceClient if a string. Assumes that the access is passwordless in that case. Otherwise, if a dictionary, options to instantiate the BlobServiceClient. Currently supported keywords: - connection_string: a connection string for the Azure blob |
None
|
compress |
bool
|
compress files inserted into the store |
False
|
sub_dir |
Optional[str]
|
(optional) subdirectory of the container to store the data. When defined, a final "/" will be added if not already present. |
None
|
workers |
int
|
number of concurrent Azure puts to run |
1
|
store_hash |
bool
|
store the sha1 hash right before insertion to the database. |
True
|
unpack_data |
bool
|
whether to decompress and unpack byte data when querying from the container. |
True
|
searchable_fields |
Optional[list[str]]
|
fields to keep in the index store |
None
|
key_sanitize_dict |
Optional[dict]
|
a dictionary that allows to customize the sanitization of the keys in metadata, since they should adhere to the naming rules for C# identifiers. If None the AZURE_KEY_SANITIZE default will be used to handle the most common cases. |
None
|
create_container |
bool
|
if True the Store creates the container, in case it does not exist. |
False
|
kwargs |
keywords for the base Store. |
{}
|
Source code in src/maggma/stores/azure.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
close()
¶
Closes any connections.
Source code in src/maggma/stores/azure.py
153 154 155 156 157 158 159 |
|
connect(*args, **kwargs)
¶
Connect to the source data.
Source code in src/maggma/stores/azure.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
count(criteria=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
Source code in src/maggma/stores/azure.py
173 174 175 176 177 178 179 180 |
|
distinct(field, criteria=None, all_exist=False)
¶
Get all distinct values for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
the field(s) to get distinct values for |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
Source code in src/maggma/stores/azure.py
241 242 243 244 245 246 247 248 249 250 |
|
ensure_index(key, unique=False)
¶
Tries to create an index and return true if it succeeded.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
single key to index |
required |
unique |
bool
|
Whether or not this index contains only unique keys |
False
|
Returns:
Type | Description |
---|---|
bool
|
bool indicating if the index exists/was created |
Source code in src/maggma/stores/azure.py
286 287 288 289 290 291 292 293 294 295 296 297 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (dict, list of docs) |
Source code in src/maggma/stores/azure.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
newer_in(target, criteria=None, exhaustive=False)
¶
Returns the keys of documents that are newer in the target Store than this Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
Store
|
target Store |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
exhaustive |
bool
|
triggers an item-by-item check vs. checking the last_updated of the target Store and using that to filter out new items in |
False
|
Source code in src/maggma/stores/azure.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
query(criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Queries the Store for a set of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Source code in src/maggma/stores/azure.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
rebuild_index_from_blob_data(**kwargs)
¶
Rebuilds the index Store from the data in Azure Relies on the index document being stores as the metadata for the file This can help recover lost databases.
Source code in src/maggma/stores/azure.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
|
rebuild_metadata_from_index(index_query=None)
¶
Read data from the index store and populate the metadata of the Azure Blob. Force all of the keys to be lower case to be Minio compatible
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index_query |
Optional[dict]
|
query on the index store. |
None
|
Source code in src/maggma/stores/azure.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
|
remove_docs(criteria, remove_blob_object=False)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
remove_blob_object |
bool
|
whether to remove the actual blob Object or not |
False
|
Source code in src/maggma/stores/azure.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
|
update(docs, key=None, additional_metadata=None)
¶
Update documents into the Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
additional_metadata |
Union[str, list[str], None]
|
field(s) to include in the blob store's metadata |
None
|
Source code in src/maggma/stores/azure.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
write_doc_to_blob(doc, search_keys)
¶
Write the data to an Azure blob and return the metadata to be inserted into the index db.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
doc |
dict
|
the document |
required |
search_keys |
list[str]
|
list of keys to pull from the docs and be inserted into the |
required |
Source code in src/maggma/stores/azure.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
Advanced Stores for behavior outside normal access patterns.
AliasingStore
¶
Bases: Store
Special Store that aliases for the primary accessors.
Source code in src/maggma/stores/advanced_stores.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
name: str
property
¶
Return a string representing this data source.
__eq__(other)
¶
Check equality for AliasingStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
other AliasingStore to compare with |
required |
Source code in src/maggma/stores/advanced_stores.py
378 379 380 381 382 383 384 385 386 387 388 389 |
|
__init__(store, aliases, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
store |
Store
|
the store to wrap around |
required |
aliases |
dict
|
dict of aliases of the form external key: internal key. |
required |
Source code in src/maggma/stores/advanced_stores.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
count(criteria=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
Source code in src/maggma/stores/advanced_stores.py
232 233 234 235 236 237 238 239 240 241 |
|
distinct(field, criteria=None, all_exist=False)
¶
Get all distinct values for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
the field(s) to get distinct values for |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
Source code in src/maggma/stores/advanced_stores.py
274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (dict, list of docs) |
Source code in src/maggma/stores/advanced_stores.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
query(criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Queries the Store for a set of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Source code in src/maggma/stores/advanced_stores.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
remove_docs(criteria)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
Source code in src/maggma/stores/advanced_stores.py
352 353 354 355 356 357 358 359 360 361 |
|
update(docs, key=None)
¶
Update documents into the Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
Source code in src/maggma/stores/advanced_stores.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
MongograntStore
¶
Bases: MongoStore
Initialize a Store with a mongogrant "<role>
:<host>
/<db>
." spec.
Some class methods of MongoStore, e.g. from_db_file and from_collection, are not supported.
mongogrant documentation: https://github.com/materialsproject/mongogrant
Source code in src/maggma/stores/advanced_stores.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
__eq__(other)
¶
Check equality for MongograntStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
other MongograntStore to compare with |
required |
Source code in src/maggma/stores/advanced_stores.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
__init__(mongogrant_spec, collection_name, mgclient_config_path=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mongogrant_spec |
str
|
of the form |
required |
collection_name |
str
|
name of mongo collection |
required |
mgclient_config_path |
Optional[str]
|
Path to mongogrant client config file,
or None if default path ( |
None
|
Source code in src/maggma/stores/advanced_stores.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
from_collection(collection)
classmethod
¶
Raises ValueError since MongograntStores can't be initialized from a PyMongo collection.
Source code in src/maggma/stores/advanced_stores.py
102 103 104 105 106 107 |
|
from_db_file(file)
classmethod
¶
Raises ValueError since MongograntStores can't be initialized from a file.
Source code in src/maggma/stores/advanced_stores.py
95 96 97 98 99 100 |
|
SandboxStore
¶
Bases: Store
Provides a sandboxed view to another store.
Source code in src/maggma/stores/advanced_stores.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
|
name: str
property
¶
Returns:
Type | Description |
---|---|
str
|
a string representing this data source. |
sbx_criteria: dict
property
¶
Returns:
Type | Description |
---|---|
dict
|
the sandbox criteria dict used to filter the source store. |
__eq__(other)
¶
Check equality for SandboxStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
other SandboxStore to compare with |
required |
Source code in src/maggma/stores/advanced_stores.py
536 537 538 539 540 541 542 543 544 545 546 547 |
|
__init__(store, sandbox, exclusive=False)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
store |
Store
|
store to wrap sandboxing around |
required |
sandbox |
str
|
the corresponding sandbox |
required |
exclusive |
bool
|
whether to be exclusively in this sandbox or include global items. |
False
|
Source code in src/maggma/stores/advanced_stores.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
count(criteria=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
Source code in src/maggma/stores/advanced_stores.py
432 433 434 435 436 437 438 439 440 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (dict, list of docs) |
Source code in src/maggma/stores/advanced_stores.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 |
|
query(criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Queries the Store for a set of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Source code in src/maggma/stores/advanced_stores.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|
remove_docs(criteria)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
Source code in src/maggma/stores/advanced_stores.py
512 513 514 515 516 517 518 519 520 521 |
|
update(docs, key=None)
¶
Update documents into the Store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
Source code in src/maggma/stores/advanced_stores.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
|
VaultStore
¶
Bases: MongoStore
Extends MongoStore to read credentials out of Vault server and uses these values to initialize MongoStore instance.
Source code in src/maggma/stores/advanced_stores.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
__eq__(other)
¶
Check equality for VaultStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
other VaultStore to compare with |
required |
Source code in src/maggma/stores/advanced_stores.py
185 186 187 188 189 190 191 192 193 194 195 196 |
|
__init__(collection_name, vault_secret_path)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_name |
str
|
name of mongo collection |
required |
vault_secret_path |
str
|
path on vault server with mongo creds object. |
required |
Important
Environment variables that must be set prior to invocation VAULT_ADDR - URL of vault server (eg. https://matgen8.lbl.gov:8200) VAULT_TOKEN or GITHUB_TOKEN - token used to authenticate to vault
Source code in src/maggma/stores/advanced_stores.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
Special stores that combine underlying Stores together.
ConcatStore
¶
Bases: Store
Store concatting multiple stores.
Source code in src/maggma/stores/compound_stores.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
|
last_updated: datetime
property
¶
Finds the most recent last_updated across all the stores. This might not be the most useful way to do this for this type of Store since it could very easily over-estimate the last_updated based on what stores are used.
name: str
property
¶
A string representing this data source.
__eq__(other)
¶
Check equality for ConcatStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
other JointStore to compare with |
required |
Source code in src/maggma/stores/compound_stores.py
512 513 514 515 516 517 518 519 520 521 522 523 |
|
__init__(stores, **kwargs)
¶
Initialize a ConcatStore that concatenates multiple stores together to appear as one store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stores |
list[Store]
|
list of stores to concatenate together |
required |
Source code in src/maggma/stores/compound_stores.py
321 322 323 324 325 326 327 328 329 330 331 |
|
close()
¶
Close all connections in this ConcatStore.
Source code in src/maggma/stores/compound_stores.py
351 352 353 354 355 356 |
|
connect(force_reset=False)
¶
Connect all stores in this ConcatStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
Whether to forcibly reset the connection for all stores |
False
|
Source code in src/maggma/stores/compound_stores.py
341 342 343 344 345 346 347 348 349 |
|
count(criteria=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
Source code in src/maggma/stores/compound_stores.py
417 418 419 420 421 422 423 424 425 426 |
|
distinct(field, criteria=None, all_exist=False)
¶
Get all distinct values for a field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
the field(s) to get distinct values for |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
Source code in src/maggma/stores/compound_stores.py
390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
ensure_index(key, unique=False)
¶
Ensure an index is properly set. Returns whether all stores support this index or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
single key to index |
required |
unique |
bool
|
Whether or not this index contains only unique keys |
False
|
Returns:
Type | Description |
---|---|
bool
|
bool indicating if the index exists/was created on all stores |
Source code in src/maggma/stores/compound_stores.py
404 405 406 407 408 409 410 411 412 413 414 415 |
|
groupby(keys, criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Simple grouping function that will group documents by keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys |
Union[list[str], str]
|
fields to group documents |
required |
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Returns:
Type | Description |
---|---|
Iterator[tuple[dict, list[dict]]]
|
generator returning tuples of (dict, list of docs) |
Source code in src/maggma/stores/compound_stores.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
query(criteria=None, properties=None, sort=None, skip=0, limit=0)
¶
Queries across all Store for a set of documents.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to search in |
None
|
properties |
Union[dict, list, None]
|
properties to return in grouped documents |
None
|
sort |
Optional[dict[str, Union[Sort, int]]]
|
Dictionary of sort order for fields. Keys are field names and values are 1 for ascending or -1 for descending. |
None
|
skip |
int
|
number documents to skip |
0
|
limit |
int
|
limit on total number of documents returned |
0
|
Source code in src/maggma/stores/compound_stores.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
remove_docs(criteria)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
Source code in src/maggma/stores/compound_stores.py
503 504 505 506 507 508 509 510 |
|
update(docs, key=None)
¶
Update documents into the Store Not implemented in ConcatStore.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docs |
Union[list[dict], dict]
|
the document or list of documents to update |
required |
key |
Union[list, str, None]
|
field name(s) to determine uniqueness for a document, can be a list of multiple fields, a single field, or None if the Store's key field is to be used |
None
|
Source code in src/maggma/stores/compound_stores.py
376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
JointStore
¶
Bases: Store
Store that implements a on-the-fly join across multiple collections all in the same MongoDB database. This is a Read-Only Store designed to combine data from multiple collections.
Source code in src/maggma/stores/compound_stores.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
last_updated: datetime
property
¶
Special last_updated for this JointStore that checks all underlying collections.
name: str
property
¶
Return a string representing this data source.
nonmain_names: list
property
¶
all non-main collection names.
__eq__(other)
¶
Check equality for JointStore
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
object
|
other JointStore to compare with. |
required |
Source code in src/maggma/stores/compound_stores.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
__init__(database, collection_names, host='localhost', port=27017, username='', password='', main=None, merge_at_root=False, mongoclient_kwargs=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database |
str
|
The database name |
required |
collection_names |
list[str]
|
list of all collections to join |
required |
host |
str
|
Hostname for the database |
'localhost'
|
port |
int
|
TCP port to connect to |
27017
|
username |
str
|
Username for the collection |
''
|
password |
str
|
Password to connect with |
''
|
main |
Optional[str]
|
name for the main collection if not specified this defaults to the first in collection_names list. |
None
|
Source code in src/maggma/stores/compound_stores.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
close()
¶
Closes underlying database connections.
Source code in src/maggma/stores/compound_stores.py
93 94 95 96 97 |
|
connect(force_reset=False)
¶
Connects the underlying Mongo database and all collection connections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force_reset |
bool
|
whether to reset the connection or not when the Store is already connected. |
False
|
Source code in src/maggma/stores/compound_stores.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
count(criteria=None)
¶
Counts the number of documents matching the query criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
Optional[dict]
|
PyMongo filter for documents to count in |
None
|
Source code in src/maggma/stores/compound_stores.py
221 222 223 224 225 226 227 228 229 230 231 |
|
ensure_index(key, unique=False, **kwargs)
¶
Can't ensure index for JointStore.
Source code in src/maggma/stores/compound_stores.py
143 144 145 146 147 |
|
query_one(criteria=None, properties=None, **kwargs)
¶
Get one document.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
properties |
properties to return in query |
None
|
|
criteria |
filter for matching |
None
|
|
kwargs |
kwargs for collection.aggregate |
{}
|
Returns:
Type | Description |
---|---|
single document |
Source code in src/maggma/stores/compound_stores.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
remove_docs(criteria)
¶
Remove docs matching the query dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
criteria |
dict
|
query dictionary to match |
required |
Source code in src/maggma/stores/compound_stores.py
288 289 290 291 292 293 294 295 |
|
update(docs, update_lu=True, key=None, **kwargs)
¶
Update documents into the underlying collections Not Implemented for JointStore.
Source code in src/maggma/stores/compound_stores.py
128 129 130 131 132 133 |
|
SSHTunnel
¶
Bases: MSONable
SSH tunnel to remote server.
Source code in src/maggma/stores/ssh_tunnel.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
__init__(tunnel_server_address, remote_server_address, local_port=None, username=None, password=None, private_key=None, **kwargs)
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tunnel_server_address |
str
|
string address with port for the SSH tunnel server |
required |
remote_server_address |
str
|
string address with port for the server to connect to |
required |
local_port |
Optional[int]
|
optional port to use for the local address (127.0.0.1);
if |
None
|
username |
Optional[str]
|
optional username for the ssh tunnel server |
None
|
password |
Optional[str]
|
optional password for the ssh tunnel server; If a private_key is supplied this password is assumed to be the private key password |
None
|
private_key |
Optional[str]
|
ssh private key to authenticate to the tunnel server |
None
|
kwargs |
any extra args passed to the SSHTunnelForwarder. |
{}
|
Source code in src/maggma/stores/ssh_tunnel.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|