{"id":19026569,"url":"https://github.com/sbdchd/mongo-types","last_synced_at":"2026-02-24T08:35:43.064Z","repository":{"id":46028895,"uuid":"313157395","full_name":"sbdchd/mongo-types","owner":"sbdchd","description":":fallen_leaf: Type stubs for mongoengine, pymongo, and bson","archived":false,"fork":false,"pushed_at":"2023-11-24T23:16:31.000Z","size":136,"stargazers_count":20,"open_issues_count":10,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-14T12:56:46.945Z","etag":null,"topics":["mongoengine","mypy","mypy-stubs","stubs","type-stubs"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbdchd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-11-16T01:06:45.000Z","updated_at":"2025-10-01T17:56:22.000Z","dependencies_parsed_at":"2023-11-12T16:29:11.631Z","dependency_job_id":"a36b3571-961c-498f-99c7-a8354755288f","html_url":"https://github.com/sbdchd/mongo-types","commit_stats":{"total_commits":77,"total_committers":5,"mean_commits":15.4,"dds":"0.24675324675324672","last_synced_commit":"71fa213472f77bfe516479d301a8de4ad8789fb9"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sbdchd/mongo-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbdchd%2Fmongo-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbdchd%2Fmongo-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbdchd%2Fmongo-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbdchd%2Fmongo-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbdchd","download_url":"https://codeload.github.com/sbdchd/mongo-types/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbdchd%2Fmongo-types/sbom","scorecard":{"id":802529,"data":{"date":"2025-08-11","repo":{"name":"github.com/sbdchd/mongo-types","commit":"84f091d751e2df61039ce636d78cc46b4385af0b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":9,"reason":"Found 29/30 approved changesets -- score normalized to 9","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":3,"reason":"7 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2024-48 / GHSA-fj7x-q9j7-g6q6","Warn: Project is vulnerable to: GHSA-3rq5-2g8h-59hc","Warn: Project is vulnerable to: GHSA-29gw-9793-fvw7","Warn: Project is vulnerable to: GHSA-m87m-mmvp-v9qm","Warn: Project is vulnerable to: PYSEC-2025-49 / GHSA-5rjg-fvgr-3xxf","Warn: Project is vulnerable to: GHSA-cx63-2mw6-8hw5","Warn: Project is vulnerable to: PYSEC-2022-43017 / GHSA-qwmp-2cf2-g9g6"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 29 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-23T10:53:43.201Z","repository_id":46028895,"created_at":"2025-08-23T10:53:43.201Z","updated_at":"2025-08-23T10:53:43.201Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29776648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-24T04:54:30.205Z","status":"ssl_error","status_checked_at":"2026-02-24T04:53:58.628Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mongoengine","mypy","mypy-stubs","stubs","type-stubs"],"created_at":"2024-11-08T20:49:42.243Z","updated_at":"2026-02-24T08:35:43.048Z","avatar_url":"https://github.com/sbdchd.png","language":"Python","readme":"# mongo-types [![PyPI](https://img.shields.io/pypi/v/mongo-types.svg)](https://pypi.org/project/mongo-types/)\n\nType stubs for [`mongoengine`][0].\n\nAllows for autocomplete and static typing.\n\n## install\n\n```shell\npip install mongo-types\n```\n\nMonkey patch mongoengine's `QuerySet` so we can type it with a generic\nargument at runtime:\n\n```python\nimport types\nfrom mongoengine.queryset.queryset import QuerySet\n\ndef no_op(self, x):\n    return self\n\nQuerySet.__class_getitem__ = types.MethodType(no_op, QuerySet)\n```\n\n## usage\n\nAfter installing and monkey patching, the types should work for the most\npart,\nbut you'll probably need to change how you write some things.\n\n### getting `objects` to work\n\nBy default, the base document is typed to not have an `objects` property so\nthat each document can type it properly.\n\nHere's a helper class that's useful for simple cases which don't modify the\n`QuerySet`.\n\n```python\nfrom typing import Generic, Type, TypeVar\nfrom mongoengine import QuerySet, Document\n\nU = TypeVar(\"U\", bound=Document)\n\nclass QuerySetManager(Generic[U]):\n    def __get__(self, instance: object, cls: Type[U]) -\u003e QuerySet[U]:\n        return QuerySet(cls, cls._get_collection())\n\nclass Page(Document):\n    meta = {\n        \"collection\": \"pages\",\n    }\n\n    objects = QuerySetManager[\"Page\"]()\n\n    organization = fields.StringField()\n```\n\n### replacing usages of `queryset_class`\n\nbefore:\n\n```python\nfrom typing import Type\nfrom mongoengine import QuerySet, Document\n\nclass PostQuerySet(QuerySet):\n    def for_org(self, *, org: str) -\u003e QuerySet:\n        return self.filter(organization=org)\n\n    def exists(self) -\u003e bool:\n        return self.count() \u003e 0\n\nclass Post(Document):\n    meta = {\n        \"collection\": \"posts\",\n        \"queryset_class\": SMSLogQuerySet,\n    }\n\n    organization = fields.StringField()\n    # --snip--\n```\n\nafter:\n\n```python\nfrom typing import Type\nfrom mongoengine import QuerySet, Document\n\nclass PostQuerySet(QuerySet[\"Post\"]):\n    def for_org(self, *, org: str) -\u003e QuerySet[\"Post\"]:\n        return self.filter(organization=org)\n\n    def exists(self) -\u003e bool:\n        return self.count() \u003e 0\n\n\nclass QuerySetManager:\n    def __get__(self, instance: object, cls: Type[Post]) -\u003e PostQuerySet:\n        return PostQuerySet(cls, cls._get_collection())\n\n\nclass Post(Document):\n    meta = {\n        \"collection\": \"posts\",\n    }\n\n    objects = QuerySetManager()\n\n    organization = fields.StringField()\n    # --snip--\n```\n\n### replicating `@queryset_manager` behavior\n\nbefore:\n\n```python\nfrom mongoengine import Document, QuerySet, queryset_manager, fields\n\nclass UserQuerySet(QuerySet):\n    def for_org(self, *, org: str) -\u003e QuerySet:\n        return self.filter(organization=org)\n\nclass User(Document):\n    meta = {\n        \"collection\": \"users\",\n        \"queryset_class\": UserQuerySet,\n    }\n\n    is_active = fields.BooleanField()\n\n    # --snip--\n\n    @queryset_manager\n    def objects(self, queryset: QuerySet) -\u003e QuerySet:\n        return queryset.filter(is_active=True)\n\n    @queryset_manager\n    def all_objects(self, queryset: QuerySet) -\u003e QuerySet:\n        return queryset\n\nmaybe_user = User.all_objects.first()\n```\n\nafter:\n\n```python\nfrom __future__ import annotations\nfrom typing import Type\nfrom mongoengine import QuerySet, Document\n\nclass UserQuerySet(QuerySet[\"User\"]):\n    def for_org(self, *, org: str) -\u003e UserQuerySet:\n        return self.filter(organization=org)\n\n\nclass QuerySetManager:\n    def __get__(self, instance: object, cls: Type[User]) -\u003e UserQuerySet:\n        return UserQuerySet(cls, cls._get_collection()).filter(is_active=True)\n\n\nclass User(Document):\n    meta = {\n        \"collection\": \"users\",\n    }\n\n    is_active = fields.BooleanField()\n\n    # --snip--\n\n    objects = QuerySetManager()\n\n    @classmethod\n    def all_objects(cls) -\u003e UserQuerySet:\n        return UserQuerySet(cls, cls._get_collection())\n\nmaybe_user = User.all_objects().first()\n```\n\n### fixing \"Model\" has no attribute \"id\"\n\nMongoengine will define an `id` field for you automatically.\nMongo-types require you specify your `id` explicitly so that\nthe types can be more strict.\n\n```python\nclass User(Document):\n    meta = {\n        \"collection\": \"users\",\n    }\n\n# becomes\n\nclass User(Document):\n    meta = {\n        \"collection\": \"users\",\n    }\n    id = fields.StringField(db_field=\"_id\", primary_key=True, default=default_id)\n\n# or if you prefer ObjectIds\n\nclass User(Document):\n    meta = {\n        \"collection\": \"users\",\n    }\n    id = fields.ObjectIdField(db_field=\"_id\", primary_key=True, default=ObjectId)\n```\n\n## dev\n\n```shell\npoetry install\n\n# run formatting, linting, and typechecking\ns/lint\n\n# build\npoetry build -f wheel\n\n# build and publish\npoetry publish --build\n```\n\n[0]: https://github.com/MongoEngine/mongoengine\n\n## related\n\n- \u003chttps://github.com/sbdchd/django-types\u003e\n- \u003chttps://github.com/sbdchd/djangorestframework-types\u003e\n- \u003chttps://github.com/sbdchd/celery-types\u003e\n- \u003chttps://github.com/sbdchd/msgpack-types\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbdchd%2Fmongo-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbdchd%2Fmongo-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbdchd%2Fmongo-types/lists"}