Skip to content

Commit

Permalink
Merge pull request #950 from rkingsbury/mgrant
Browse files Browse the repository at this point in the history
MongograntStore: make optional dependency, prepare for removal
  • Loading branch information
rkingsbury committed May 27, 2024
2 parents f944d10 + 4b62290 commit f88951d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
10 changes: 6 additions & 4 deletions docs/getting_started/advanced_stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ Different S3 services might have different rules, but the limit is typically sma
The `S3Store` should be constructed as follows:

```python
from maggma.stores import MongograntStore, S3Store
index = MongograntStore("ro:mongodb03/js_cathodes",
"atomate_aeccar0_fs_index",
key="fs_id")
from maggma.stores import MongoURIStore, S3Store
store = MongoURIStore(
"mongodb+srv://<username>:<password>@<host>",
"atomate_aeccar0_fs_index",
key="fs_id",
)
s3store = S3Store(index=index,
bucket="<<BUCKET_NAME>>",
s3_profile="<<S3_PROFILE_NAME>>",
Expand Down
9 changes: 5 additions & 4 deletions docs/getting_started/stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ The benefit of the `Store` interface is that you only have to write a `Builder`

Current working and tested `Store` include:

- `MongoStore`: interfaces to a MongoDB Collection
- `MongoStore`: interfaces to a MongoDB Collection using port and hostname.
- `MongoURIStore`: interfaces to a MongoDB Collection using a "mongodb+srv://" URI.
- `MemoryStore`: just a Store that exists temporarily in memory
- `JSONStore`: builds a MemoryStore and then populates it with the contents of the given JSON files
- `FileStore`: query and add metadata to files stored on disk as if they were in a database
- `GridFSStore`: interfaces to GridFS collection in MongoDB
- `GridFSStore`: interfaces to GridFS collection in MongoDB using port and hostname.
- `GridFSURIStore`: interfaces to GridFS collection in MongoDB using a "mongodb+srv://" URI.
- `S3Store`: provides an interface to an S3 Bucket either on AWS or self-hosted solutions ([additional documentation](advanced_stores.md))
- `ConcatStore`: concatenates several Stores together so they look like one Store
- `MongoURIStore`: MongoDB Introduced advanced URIs including their special "mongodb+srv://" which uses a combination of SRV and TXT DNS records to fully setup the client. This store is to safely handle these kinds of URIs.
- `MongograntStore`: uses Mongogrant to get credentials for MongoDB database
- `VaultStore`: uses Vault to get credentials for a MongoDB database
- `AliasingStore`: aliases keys from the underlying store to new names
- `SandboxStore: provides permission control to documents via a `_sbxn` sandbox key
- `JointStore`: joins several MongoDB collections together, merging documents with the same `key`, so they look like one collection
- `AzureBlobStore`: provides an interface to Azure Blobs for the storage of large amount of data
- `MontyStore`: provides an interface to [montydb](https://github.com/davidlatwe/montydb) for in-memory or filesystem-based storage
- `MongograntStore`: (DEPRECATED) uses Mongogrant to get credentials for MongoDB database

## The `Store` interface

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"pydantic>=2.0",
"pydantic-settings>=2.0.3",
"pymongo>=4.2.0",
"monty>=2023.9.25",
"monty>=2024.5.24",
"mongomock>=3.10.0",
"pydash>=4.1.0",
"jsonschema>=3.1.1",
Expand Down
16 changes: 12 additions & 4 deletions src/maggma/stores/advanced_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
from collections.abc import Iterator
from typing import Optional, Union

from mongogrant import Client
from mongogrant.client import check
from mongogrant.config import Config
from monty.dev import requires
from monty.dev import deprecated, requires

from maggma.core import Sort, Store, StoreError
from maggma.stores.mongolike import MongoStore
Expand All @@ -19,8 +16,15 @@
import hvac
except ImportError:
hvac = None
try:
from mongogrant import Client
from mongogrant.client import check
from mongogrant.config import Config
except ImportError:
Client = None


@deprecated(MongoStore)
class MongograntStore(MongoStore):
"""Initialize a Store with a mongogrant "`<role>`:`<host>`/`<db>`." spec.
Expand All @@ -30,6 +34,10 @@ class MongograntStore(MongoStore):
mongogrant documentation: https://github.com/materialsproject/mongogrant
"""

@requires(
Client is not None,
"mongogrant is required to use MongoGrantStore. Please run `pip install maggma[mongogrant]",
)
def __init__(
self,
mongogrant_spec: str,
Expand Down

0 comments on commit f88951d

Please sign in to comment.