mimicker


Namemimicker JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/amaziahub/mimicker
SummaryA lightweight HTTP mocking server for Python
upload_time2024-11-13 13:20:00
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)
[![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/a3/40/64eb705df27aabd644063ef57fe9d942e851ef3aa14781c603d5330f426e/mimicker-0.1.2.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[![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.2",
    "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": "37354cea4a4f47e0b5db03d881475dfc828381ae65f3a00b69027a7cc43f670f",
                "md5": "63ccf20d3bfc5eaa0806b630edc4cfd2",
                "sha256": "e0ddeac5956c29d7a083b1195fe70a0f11c9118c9abba0660d36e0e6001adf4e"
            },
            "downloads": -1,
            "filename": "mimicker-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "63ccf20d3bfc5eaa0806b630edc4cfd2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.7",
            "size": 10536,
            "upload_time": "2024-11-13T13:19:59",
            "upload_time_iso_8601": "2024-11-13T13:19:59.256232Z",
            "url": "https://files.pythonhosted.org/packages/37/35/4cea4a4f47e0b5db03d881475dfc828381ae65f3a00b69027a7cc43f670f/mimicker-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a34064eb705df27aabd644063ef57fe9d942e851ef3aa14781c603d5330f426e",
                "md5": "17c96c120f27b6bd556a9311edc0a187",
                "sha256": "7e9929a5b70c312b2c2196c15b586dbb399b383ff4d7b221320f275d1edae575"
            },
            "downloads": -1,
            "filename": "mimicker-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "17c96c120f27b6bd556a9311edc0a187",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.7",
            "size": 8817,
            "upload_time": "2024-11-13T13:20:00",
            "upload_time_iso_8601": "2024-11-13T13:20:00.903895Z",
            "url": "https://files.pythonhosted.org/packages/a3/40/64eb705df27aabd644063ef57fe9d942e851ef3aa14781c603d5330f426e/mimicker-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-13 13:20:00",
    "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.78262s