ModuleNotFoundError: No module named 'moto.moto_server.backends'
Fixes code reaching into moto's internals for the backend registry after moto 3 reorganized them. Use when importing backends from moto.moto_server fails. Not for mock decorator import errors.
TL;DR: moto 3.0.7 moved its internal backend registry. Stop importing it from moto.server or moto.motoserver and use the supported path: import moto.backends, then moto.backends.getbackend("s3").
>>> import moto.moto_server.backends
Traceback (most recent call last):
...
ModuleNotFoundError: No module named 'moto.moto_server.backends'Fix it
- Change the import to the supported location: import moto.backends. Expected: imports cleanly.
- Get a backend via the registry: moto.backends.get_backend("s3"). Expected: returns the S3 backend class.
- Grep your codebase for other deep imports (moto.server.backends, moto.backends BackendsLoader internals). Expected: only the supported path remains.
- If you cannot change the code yet: pin moto to 3.0.5 in test requirements. Expected: old paths work, temporarily.
When this applies
- The import of moto.moto_server.backends (or attribute access on moto.server.backends) fails on moto 3.0.6+.
When it doesn't
- from moto import mocks3 fails: that is the decorator rename (moto 5) or the mocks3 removal, a different problem.
- You are on moto 5: the backends module still exists, but most test code should just use mock_aws.
Compatibility
- moto 3.x. The supported import moto.backends works across 3.x and later.
Why it happens
moto reorganized its server-mode internals between patch releases and the old dotted paths stopped existing. Reaching into undocumented internals is fragile by nature; the registry accessor is the stable entry point.
Edge cases
- Pin moto in CI: patch releases have moved internals before, so unpinned upgrades can break suites overnight.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.