Official Python SDK for Mockarty — multi-protocol mock server for HTTP, gRPC, MCP, GraphQL, SOAP, SSE, Kafka, RabbitMQ, SMTP
Project description
Python SDK
Official Python client library for Mockarty — a multi-protocol mock server for HTTP, gRPC, MCP, GraphQL, SOAP, SSE, WebSocket, Kafka, RabbitMQ, and SMTP.
Installation
pip install mockarty
For async HTTP/2 support:
pip install mockarty[async]
Quick Start
Synchronous Client
from mockarty import MockartyClient, MockBuilder, AssertAction
# Create a client
client = MockartyClient(
base_url="http://localhost:5770",
api_key="your-api-key",
namespace="sandbox",
)
# Create a mock using the builder
mock = (
MockBuilder.http("/api/users/:id", "GET")
.id("user-get")
.respond(200, body={"id": "$.pathParam.id", "name": "$.fake.FirstName"})
.ttl(3600)
.build()
)
result = client.mocks.create(mock)
print(f"Created mock: {result.mock.id}")
# List mocks
page = client.mocks.list(namespace="sandbox", limit=10)
for m in page.items:
print(f" {m.id}")
# Health check
health = client.health.check()
print(f"Status: {health.status}")
client.close()
Async Client
import asyncio
from mockarty import AsyncMockartyClient, MockBuilder
async def main():
async with AsyncMockartyClient(base_url="http://localhost:5770") as client:
mock = MockBuilder.http("/api/hello", "GET").respond(200, body={"msg": "hello"}).build()
result = await client.mocks.create(mock)
print(f"Created: {result.mock.id}")
asyncio.run(main())
Context Manager
with MockartyClient() as client:
client.mocks.create(mock)
# client.close() is called automatically
Mock Builder
from mockarty import MockBuilder, AssertAction
# HTTP mock with conditions
mock = (
MockBuilder.http("/api/orders", "POST")
.id("create-order")
.namespace("production")
.tags("orders", "v2")
.priority(10)
.condition("$.body.amount", AssertAction.NOT_EMPTY)
.header_condition("Authorization", AssertAction.NOT_EMPTY)
.respond(201, body={
"orderId": "$.fake.UUID",
"amount": "$.req.amount",
"status": "created",
})
.callback("https://webhook.site/test", method="POST", body={"event": "order.created"})
.ttl(7200)
.build()
)
# gRPC mock
grpc_mock = (
MockBuilder.grpc("user.UserService", "GetUser")
.id("grpc-get-user")
.condition("$.id", AssertAction.NOT_EMPTY)
.respond(200, body={"id": "$.req.id", "name": "$.fake.FirstName"})
.build()
)
# MCP mock
mcp_mock = (
MockBuilder.mcp("get_weather")
.id("mcp-weather")
.respond(200, body={"temperature": 22, "city": "$.req.city"})
.build()
)
Working with Stores
with MockartyClient() as client:
# Global store
client.stores.global_set("counter", 0)
data = client.stores.global_get()
print(data) # {"counter": 0}
# Chain store
client.stores.chain_set("order-flow", "orderId", "abc-123")
chain_data = client.stores.chain_get("order-flow")
print(chain_data) # {"orderId": "abc-123"}
Error Handling
from mockarty import MockartyClient
from mockarty.errors import MockartyNotFoundError, MockartyAPIError
client = MockartyClient()
try:
mock = client.mocks.get("non-existent")
except MockartyNotFoundError:
print("Mock not found")
except MockartyAPIError as e:
print(f"API error {e.status_code}: {e.message}")
Configuration
The client reads these environment variables as defaults:
| Variable | Description | Default |
|---|---|---|
MOCKARTY_BASE_URL |
Mockarty server URL | http://localhost:5770 |
MOCKARTY_API_KEY |
API authentication key | None |
pytest Integration
Install the test extras:
pip install mockarty[test]
Use the provided fixtures in your tests:
# conftest.py
pytest_plugins = ["mockarty.testing.fixtures"]
# test_example.py
def test_create_mock(mock_cleanup):
from mockarty import MockBuilder
mock = MockBuilder.http("/test", "GET").respond(200, body="ok").build()
created = mock_cleanup(mock)
assert created.id is not None
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mockarty-0.1.0.tar.gz.
File metadata
- Download URL: mockarty-0.1.0.tar.gz
- Upload date:
- Size: 31.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5d1a909f5466debb13597df44f844aa96de0f4aa3d3ad63266570c951fb3526
|
|
| MD5 |
6d33c7766e5e1f31e40d7759a3c40653
|
|
| BLAKE2b-256 |
2ddf646a963da853dc33c7b7bf3a0358d6ef9a786629e36ba6e9e5bd5e33ac78
|
Provenance
The following attestation bundles were made for mockarty-0.1.0.tar.gz:
Publisher:
publish.yml on mockarty/py-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mockarty-0.1.0.tar.gz -
Subject digest:
e5d1a909f5466debb13597df44f844aa96de0f4aa3d3ad63266570c951fb3526 - Sigstore transparency entry: 1181173918
- Sigstore integration time:
-
Permalink:
mockarty/py-sdk@548b786befa24b763c5ef34ddea5d23e70621dda -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mockarty
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@548b786befa24b763c5ef34ddea5d23e70621dda -
Trigger Event:
push
-
Statement type:
File details
Details for the file mockarty-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mockarty-0.1.0-py3-none-any.whl
- Upload date:
- Size: 55.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b9de037f1ace9689e96cab8fe99c92875f81f8b1c29398f01b07338f87383cb
|
|
| MD5 |
dab0f7ad380b07ceac7ad5440f1043c2
|
|
| BLAKE2b-256 |
85b9f682e774622f2df64ea6a7aad9ace0251645fbca73df1fada60244efc5ca
|
Provenance
The following attestation bundles were made for mockarty-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on mockarty/py-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mockarty-0.1.0-py3-none-any.whl -
Subject digest:
1b9de037f1ace9689e96cab8fe99c92875f81f8b1c29398f01b07338f87383cb - Sigstore transparency entry: 1181173928
- Sigstore integration time:
-
Permalink:
mockarty/py-sdk@548b786befa24b763c5ef34ddea5d23e70621dda -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mockarty
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@548b786befa24b763c5ef34ddea5d23e70621dda -
Trigger Event:
push
-
Statement type: