Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Document object mapper for pydantic and pymongo
pip install pydantic-mongo
from bson import ObjectId
from pydantic import BaseModel
from pydantic_mongo import AbstractRepository, PydanticObjectId
from pymongo import MongoClient
from typing import Optional, List
import os
class Foo(BaseModel):
count: int
size: float = None
class Bar(BaseModel):
apple: str = 'x'
banana: str = 'y'
class Spam(BaseModel):
# PydanticObjectId is an alias to Annotated[ObjectId, ObjectIdAnnotation]
id: Optional[PydanticObjectId] = None
foo: Foo
bars: List[Bar]
class SpamRepository(AbstractRepository[Spam]):
class Meta:
collection_name = 'spams'
client = MongoClient("mongodb://localhost:27017")
database = client["example"]
spam = Spam(foo=Foo(count=1, size=1.0),bars=[Bar()])
spam_with_predefined_id = Spam(
id=ObjectId("611827f2878b88b49ebb69fc"),
foo=Foo(count=2, size=2.0),
bars=[Bar()]
)
spam_repository = SpamRepository(database=database)
# Insert / Update
spam_repository.save(spam)
# Insert / Update many items
spam_repository.save_many([spam, spam_with_predefined_id])
# Delete
spam_repository.delete(spam)
# Find One By Id
result = spam_repository.find_one_by_id(spam.id)
# Find One By Id using string if the id attribute is a PydanticObjectId
result = spam_repository.find_one_by_id(ObjectId('611827f2878b88b49ebb69fc'))
assert result.foo.count == 2
# Find One By Query
result = spam_repository.find_one_by({'foo.count': 1})
# Find By Query
results = spam_repository.find_by({'foo.count': {'$gte': 1}})
# Paginate using cursor based pagination
edges = spam_repository.paginate({'foo.count': {'$gte': 1}}, limit=1)
more_edges = spam_repository.paginate({'foo.count': {'$gte': 1}}, limit=1, after=list(edges)[-1].cursor)
FAQs
Document object mapper for pydantic and pymongo
We found that pydantic-mongo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.