mimicker


Namemimicker JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/amaziahub/mimicker
SummaryA lightweight HTTP mocking server for Python
upload_time2024-12-12 18:51:16
maintainerNone
docs_urlNone
authorAmazia Gur
requires_python<4.0,>=3.7
licenseMIT
keywords http mocking testing mock-server stubbing ci-cd http-server testing-tools stub-server purepython
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="https://raw.githubusercontent.com/amaziahub/mimicker/main/mimicker.jpg" alt="Mimicker logo" 
       style="width: 200px; height: auto; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); border: 2px solid black;">
</p>
<div>

<div align="center">

> **Mimicker** – Your lightweight, Python-native HTTP mocking server.

</div>

<div align="center">

[![Mimicker Tests](https://github.com/amaziahub/mimicker/actions/workflows/test.yml/badge.svg)](https://github.com/amaziahub/mimicker/actions/workflows/test.yml)
[![PyPI Version](https://img.shields.io/pypi/v/mimicker.svg)](https://pypi.org/project/mimicker/)
[![Downloads](https://pepy.tech/badge/mimicker)](https://pepy.tech/project/mimicker)
[![Last Commit](https://img.shields.io/github/last-commit/amaziahub/mimicker.svg)](https://github.com/amaziahub/mimicker/commits/main)
[![Codecov Coverage](https://codecov.io/gh/amaziahub/mimicker/branch/main/graph/badge.svg?token=YOUR_CODECOV_TOKEN)](https://codecov.io/gh/amaziahub/mimicker)
[![License](http://img.shields.io/:license-apache2.0-red.svg)](http://doge.mit-license.org)
![Poetry](https://img.shields.io/badge/managed%20with-poetry-blue)

</div>
</div>


Mimicker is a Python-native HTTP mocking server inspired by WireMock, designed to simplify the process of stubbing and
mocking HTTP endpoints for testing purposes.
Mimicker requires no third-party libraries and is lightweight, making it ideal for integration testing, local
development, and CI environments.

## Features

- Create HTTP stubs for various endpoints and methods
- Mock responses with specific status codes, headers, and body content
- Flexible configuration for multiple endpoints

## Installation

Mimicker can be installed directly from PyPI using pip or Poetry:

### Using pip:

```bash
pip install mimicker
```

### Using poetry:

```bash
poetry add mimicker
```

## Usage

To start Mimicker on a specific port with a simple endpoint, you can use the following code snippet:

```python
from mimicker.mimicker import mimicker, get

mimicker(8080).routes(
    get("/hello").
    body({"message": "Hello, World!"}).
    status(200)
)
```

### Examples

#### Using Path Parameters

Mimicker can handle path parameters dynamically. Here's how you can mock an endpoint with a variable in the path:

```python
from mimicker.mimicker import mimicker, get

mimicker(8080).routes(
    get("/hello/{name}")
    .body({"message": "Hello, {name}!"})
    .status(200)
)

# When the client sends a request to /hello/world, the response will be:
# {"message": "Hello, world!"}
```

#### Using Headers

You can also mock responses with custom headers:

```python
from mimicker.mimicker import mimicker, get

mimicker(8080).routes(
    get("/hello")
    .body("Hello with headers")
    .headers([("Content-Type", "text/plain"), ("Custom-Header", "Value")])
    .status(200)
)

# The response will include custom headers
```

#### Multiple Routes

Mimicker allows you to define multiple routes for different HTTP methods and paths. Here's an example with `GET`
and `POST` routes:

```python
from mimicker.mimicker import mimicker, get, post

mimicker(8080).routes(
    get("/greet")
    .body({"message": "Hello, world!"})
    .status(200),

    post("/submit")
    .body({"result": "Submission received"})
    .status(201)
)

# Now the server responds to:
# GET /greet -> {"message": "Hello, world!"}
# POST /submit -> {"result": "Submission received"}

```

#### Handling Different Status Codes

You can also mock different HTTP status codes for the same endpoint:

```python
from mimicker.mimicker import mimicker, get

mimicker(8080).routes(
    get("/status")
    .body({"message": "Success"})
    .status(200),

    get("/error")
    .body({"message": "Not Found"})
    .status(404)
)

# GET /status -> {"message": "Success"} with status 200
# GET /error -> {"message": "Not Found"} with status 404
```

#### Mocking Responses with JSON Body

Mimicker supports JSON bodies, making it ideal for API testing:

```python
from mimicker.mimicker import mimicker, get

mimicker(8080).routes(
    get("/json")
    .body({"message": "Hello, JSON!"})
    .status(200)
)

# The response will be: {"message": "Hello, JSON!"}
```

#### Supporting Other Body Types (Text, Files, etc.)

In addition to JSON bodies, Mimicker supports other types of content for the response body. Here's how you can return
text or file content:

##### Text Response:

```python
from mimicker.mimicker import mimicker, get

mimicker(8080).routes(
    get("/text")
    .body("This is a plain text response")
    .status(200)
)

# The response will be plain text: "This is a plain text response"
```

#### File Response:

You can also return files from a mock endpoint:

```python
from mimicker.mimicker import mimicker, get

mimicker(8080).routes(
    get("/file")
    .body(open("example.txt", "rb").read())  # Mock a file response
    .status(200)
)

# The response will be the content of the "example.txt" file

```

## Available Features:

* `get(path)`: Defines a `GET` endpoint.
* `post(path)`: Defines a `POST` endpoint.
* `put(path)`: Defines a `PUT` endpoint.
* `delete(path)`: Defines a `DELETE` endpoint.
* `.body(content)`: Defines the response `body`.
* `.status(code)`: Defines the response `status code`.
* `.headers(headers)`: Defines response `headers`.

## Requirements
Mimicker supports Python 3.7 and above.


## License
Mimicker is released under the MIT License. see the [LICENSE](LICENSE) for more information.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/amaziahub/mimicker",
    "name": "mimicker",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.7",
    "maintainer_email": null,
    "keywords": "http, mocking, testing, mock-server, stubbing, ci-cd, http-server, testing-tools, stub-server, purepython",
    "author": "Amazia Gur",
    "author_email": "amaziagur@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/03/4a/c7108d32ed1e436f7f4fcab632ffbf56c63c834a34557f3085bb023244da/mimicker-0.1.3.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/amaziahub/mimicker/main/mimicker.jpg\" alt=\"Mimicker logo\" \n       style=\"width: 200px; height: auto; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); border: 2px solid black;\">\n</p>\n<div>\n\n<div align=\"center\">\n\n> **Mimicker** \u2013 Your lightweight, Python-native HTTP mocking server.\n\n</div>\n\n<div align=\"center\">\n\n[![Mimicker Tests](https://github.com/amaziahub/mimicker/actions/workflows/test.yml/badge.svg)](https://github.com/amaziahub/mimicker/actions/workflows/test.yml)\n[![PyPI Version](https://img.shields.io/pypi/v/mimicker.svg)](https://pypi.org/project/mimicker/)\n[![Downloads](https://pepy.tech/badge/mimicker)](https://pepy.tech/project/mimicker)\n[![Last Commit](https://img.shields.io/github/last-commit/amaziahub/mimicker.svg)](https://github.com/amaziahub/mimicker/commits/main)\n[![Codecov Coverage](https://codecov.io/gh/amaziahub/mimicker/branch/main/graph/badge.svg?token=YOUR_CODECOV_TOKEN)](https://codecov.io/gh/amaziahub/mimicker)\n[![License](http://img.shields.io/:license-apache2.0-red.svg)](http://doge.mit-license.org)\n![Poetry](https://img.shields.io/badge/managed%20with-poetry-blue)\n\n</div>\n</div>\n\n\nMimicker is a Python-native HTTP mocking server inspired by WireMock, designed to simplify the process of stubbing and\nmocking HTTP endpoints for testing purposes.\nMimicker requires no third-party libraries and is lightweight, making it ideal for integration testing, local\ndevelopment, and CI environments.\n\n## Features\n\n- Create HTTP stubs for various endpoints and methods\n- Mock responses with specific status codes, headers, and body content\n- Flexible configuration for multiple endpoints\n\n## Installation\n\nMimicker can be installed directly from PyPI using pip or Poetry:\n\n### Using pip:\n\n```bash\npip install mimicker\n```\n\n### Using poetry:\n\n```bash\npoetry add mimicker\n```\n\n## Usage\n\nTo start Mimicker on a specific port with a simple endpoint, you can use the following code snippet:\n\n```python\nfrom mimicker.mimicker import mimicker, get\n\nmimicker(8080).routes(\n    get(\"/hello\").\n    body({\"message\": \"Hello, World!\"}).\n    status(200)\n)\n```\n\n### Examples\n\n#### Using Path Parameters\n\nMimicker can handle path parameters dynamically. Here's how you can mock an endpoint with a variable in the path:\n\n```python\nfrom mimicker.mimicker import mimicker, get\n\nmimicker(8080).routes(\n    get(\"/hello/{name}\")\n    .body({\"message\": \"Hello, {name}!\"})\n    .status(200)\n)\n\n# When the client sends a request to /hello/world, the response will be:\n# {\"message\": \"Hello, world!\"}\n```\n\n#### Using Headers\n\nYou can also mock responses with custom headers:\n\n```python\nfrom mimicker.mimicker import mimicker, get\n\nmimicker(8080).routes(\n    get(\"/hello\")\n    .body(\"Hello with headers\")\n    .headers([(\"Content-Type\", \"text/plain\"), (\"Custom-Header\", \"Value\")])\n    .status(200)\n)\n\n# The response will include custom headers\n```\n\n#### Multiple Routes\n\nMimicker allows you to define multiple routes for different HTTP methods and paths. Here's an example with `GET`\nand `POST` routes:\n\n```python\nfrom mimicker.mimicker import mimicker, get, post\n\nmimicker(8080).routes(\n    get(\"/greet\")\n    .body({\"message\": \"Hello, world!\"})\n    .status(200),\n\n    post(\"/submit\")\n    .body({\"result\": \"Submission received\"})\n    .status(201)\n)\n\n# Now the server responds to:\n# GET /greet -> {\"message\": \"Hello, world!\"}\n# POST /submit -> {\"result\": \"Submission received\"}\n\n```\n\n#### Handling Different Status Codes\n\nYou can also mock different HTTP status codes for the same endpoint:\n\n```python\nfrom mimicker.mimicker import mimicker, get\n\nmimicker(8080).routes(\n    get(\"/status\")\n    .body({\"message\": \"Success\"})\n    .status(200),\n\n    get(\"/error\")\n    .body({\"message\": \"Not Found\"})\n    .status(404)\n)\n\n# GET /status -> {\"message\": \"Success\"} with status 200\n# GET /error -> {\"message\": \"Not Found\"} with status 404\n```\n\n#### Mocking Responses with JSON Body\n\nMimicker supports JSON bodies, making it ideal for API testing:\n\n```python\nfrom mimicker.mimicker import mimicker, get\n\nmimicker(8080).routes(\n    get(\"/json\")\n    .body({\"message\": \"Hello, JSON!\"})\n    .status(200)\n)\n\n# The response will be: {\"message\": \"Hello, JSON!\"}\n```\n\n#### Supporting Other Body Types (Text, Files, etc.)\n\nIn addition to JSON bodies, Mimicker supports other types of content for the response body. Here's how you can return\ntext or file content:\n\n##### Text Response:\n\n```python\nfrom mimicker.mimicker import mimicker, get\n\nmimicker(8080).routes(\n    get(\"/text\")\n    .body(\"This is a plain text response\")\n    .status(200)\n)\n\n# The response will be plain text: \"This is a plain text response\"\n```\n\n#### File Response:\n\nYou can also return files from a mock endpoint:\n\n```python\nfrom mimicker.mimicker import mimicker, get\n\nmimicker(8080).routes(\n    get(\"/file\")\n    .body(open(\"example.txt\", \"rb\").read())  # Mock a file response\n    .status(200)\n)\n\n# The response will be the content of the \"example.txt\" file\n\n```\n\n## Available Features:\n\n* `get(path)`: Defines a `GET` endpoint.\n* `post(path)`: Defines a `POST` endpoint.\n* `put(path)`: Defines a `PUT` endpoint.\n* `delete(path)`: Defines a `DELETE` endpoint.\n* `.body(content)`: Defines the response `body`.\n* `.status(code)`: Defines the response `status code`.\n* `.headers(headers)`: Defines response `headers`.\n\n## Requirements\nMimicker supports Python 3.7 and above.\n\n\n## License\nMimicker is released under the MIT License. see the [LICENSE](LICENSE) for more information.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight HTTP mocking server for Python",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/amaziahub/mimicker",
        "Repository": "https://github.com/amaziahub/mimicker"
    },
    "split_keywords": [
        "http",
        " mocking",
        " testing",
        " mock-server",
        " stubbing",
        " ci-cd",
        " http-server",
        " testing-tools",
        " stub-server",
        " purepython"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56a334f2f8ca8e0ccf4a2e63570b3e8b62d471a6d7f1f443bdb4addd83ed2711",
                "md5": "9057ffe5e421d6c5d78def666db70dc9",
                "sha256": "51aa7eac7b4d164915cde817235504f2c917058fea6d6a622b872d2ecc3456a0"
            },
            "downloads": -1,
            "filename": "mimicker-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9057ffe5e421d6c5d78def666db70dc9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 10683,
            "upload_time": "2024-12-12T18:51:14",
            "upload_time_iso_8601": "2024-12-12T18:51:14.497894Z",
            "url": "https://files.pythonhosted.org/packages/56/a3/34f2f8ca8e0ccf4a2e63570b3e8b62d471a6d7f1f443bdb4addd83ed2711/mimicker-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "034ac7108d32ed1e436f7f4fcab632ffbf56c63c834a34557f3085bb023244da",
                "md5": "0aeaf249679005100c28ef1a14b5d402",
                "sha256": "7369e848bfdf4a22f9d4f6bbdf3c0b6e0836fec6fbca359b1bd936ee59d70678"
            },
            "downloads": -1,
            "filename": "mimicker-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "0aeaf249679005100c28ef1a14b5d402",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 8983,
            "upload_time": "2024-12-12T18:51:16",
            "upload_time_iso_8601": "2024-12-12T18:51:16.800782Z",
            "url": "https://files.pythonhosted.org/packages/03/4a/c7108d32ed1e436f7f4fcab632ffbf56c63c834a34557f3085bb023244da/mimicker-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-12 18:51:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "amaziahub",
    "github_project": "mimicker",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mimicker"
}
        
Elapsed time: 0.75672s