2017-02-24 00:43:48 +00:00
# Moto - Mock AWS Services
2013-02-16 03:15:43 +00:00
2017-05-12 23:51:37 +00:00
[![Join the chat at https://gitter.im/awsmoto/Lobby ](https://badges.gitter.im/awsmoto/Lobby.svg )](https://gitter.im/awsmoto/Lobby?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2023-01-07 11:35:14 +00:00
[![Build Status ](https://github.com/getmoto/moto/workflows/TestNDeploy/badge.svg )](https://github.com/getmoto/moto/actions)
[![Coverage Status ](https://codecov.io/gh/getmoto/moto/branch/master/graph/badge.svg )](https://codecov.io/gh/getmoto/moto)
2017-03-15 03:20:17 +00:00
[![Docs ](https://readthedocs.org/projects/pip/badge/?version=stable )](http://docs.getmoto.org)
2021-01-31 13:15:04 +00:00
[![PyPI ](https://img.shields.io/pypi/v/moto.svg )](https://pypi.org/project/moto/)
[![PyPI - Python Version ](https://img.shields.io/pypi/pyversions/moto.svg )](#)
[![PyPI - Downloads ](https://img.shields.io/pypi/dw/moto.svg )](https://pypistats.org/packages/moto)
[![Code style: Ruff ](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json )](https://github.com/astral-sh/ruff)
2023-06-02 10:45:02 +00:00
[![Financial Contributors ](https://opencollective.com/moto/tiers/badge.svg )](https://opencollective.com/moto)
2013-03-01 03:36:23 +00:00
2020-09-13 15:08:23 +00:00
## Install
```console
2022-05-16 16:59:53 +00:00
$ pip install 'moto[ec2,s3,all]'
2020-09-13 15:08:23 +00:00
```
2019-10-27 01:47:45 +00:00
## In a nutshell
2013-02-16 03:15:43 +00:00
2021-11-08 12:02:46 +00:00
2017-02-24 00:43:48 +00:00
Moto is a library that allows your tests to easily mock out AWS Services.
2013-02-16 03:15:43 +00:00
2017-02-24 00:43:48 +00:00
Imagine you have the following python code that you want to test:
2013-02-16 03:15:43 +00:00
```python
2017-02-24 00:43:48 +00:00
import boto3
2013-02-16 03:15:43 +00:00
2022-12-22 14:34:17 +00:00
class MyModel:
2013-02-16 03:15:43 +00:00
def __init__ (self, name, value):
self.name = name
self.value = value
def save(self):
2022-12-22 14:34:17 +00:00
s3 = boto3.client("s3", region_name="us-east-1")
s3.put_object(Bucket="mybucket", Key=self.name, Body=self.value)
2013-02-16 03:15:43 +00:00
```
Take a minute to think how you would have tested that in the past.
2013-03-01 03:45:41 +00:00
Now see how you could test it with Moto:
2013-02-16 03:15:43 +00:00
```python
2017-02-24 00:43:48 +00:00
import boto3
2024-01-29 18:15:41 +00:00
from moto import mock_aws
2013-02-16 03:15:43 +00:00
from mymodule import MyModel
2022-12-22 14:34:17 +00:00
2024-01-29 18:15:41 +00:00
@mock_aws
2013-02-16 03:15:43 +00:00
def test_my_model_save():
2022-12-22 14:34:17 +00:00
conn = boto3.resource("s3", region_name="us-east-1")
2013-09-24 14:44:25 +00:00
# We need to create the bucket since this is all in Moto's 'virtual' AWS account
2022-12-22 14:34:17 +00:00
conn.create_bucket(Bucket="mybucket")
model_instance = MyModel("steve", "is awesome")
2013-02-16 03:15:43 +00:00
model_instance.save()
2022-12-22 14:34:17 +00:00
body = conn.Object("mybucket", "steve").get()["Body"].read().decode("utf-8")
assert body == "is awesome"
2013-02-16 03:15:43 +00:00
```
2023-10-28 08:09:38 +00:00
With the decorator wrapping the test, all the calls to s3 are automatically mocked out. The mock keeps track of the state of the buckets and keys.
2013-02-16 03:15:43 +00:00
2023-01-07 11:35:14 +00:00
For a full list of which services and features are covered, please see our [implementation coverage ](https://github.com/getmoto/moto/blob/master/IMPLEMENTATION_COVERAGE.md ).
2019-07-01 03:31:21 +00:00
2021-11-08 12:02:46 +00:00
### Documentation
The full documentation can be found here:
2019-07-01 03:31:21 +00:00
2022-05-16 16:59:53 +00:00
[http://docs.getmoto.org/en/latest/ ](http://docs.getmoto.org/en/latest/ )
2023-04-14 09:52:02 +00:00
2023-06-02 10:45:02 +00:00
### Financial Contributions
2023-10-28 08:09:38 +00:00
Support this project and its continued development, by sponsoring us!
2023-06-02 10:45:02 +00:00
Click the `Sponsor` -button at the top of the page for more information.
Our finances are managed by OpenCollective, which means you have full visibility into all our contributions and expenses:
https://opencollective.com/moto
2023-04-14 09:52:02 +00:00
### Security contact information
To report a security vulnerability, please use the
[Tidelift security contact ](https://tidelift.com/security ).
Tidelift will coordinate the fix and disclosure.