atomic-bomb-engine-py
atomic-bomb-engine的python包装实现
使用条件:
- python版本 >= 3.8
- windows(x86), linux(x86), mac
使用方法:
通过pip安装
pip install atomic-bomb-engine-py
在python中引用时注意,需要引用atomic_bomb_engine, 而不是atomic_bomb_engine_py
import atomic_bomb_engine
异步使用的时候,还需要引用asyncio
import asyncio
-
开始压测
- 单接口压测
单接口压测可以使用run_async方法 函数签名和解释如下
async def run_async( url: str, method: str, test_duration_secs: int, concurrent_requests: int, timeout_secs: int, verbose: bool = False, json_str: str | None = None, form_data_str: str | None = None, headers: str | None = None, cookie: str | None = None, should_prevent:bool = False, assert_options: List[Dict[str, Any]] | None ) -> dict: """ 异步启动压测引擎 :param url: 压测地址 :param method: 请求方式 :param test_duration_secs: 持续时间 :param concurrent_requests: 并发量 :param timeout_secs: 接口超时时间 :param verbose: 开启详情日志 :param json_str: 使用json请求发送请求,使用json字符串,不要使用字典类型 :param form_data_str: 使用form方式发送请求 :param headers: 添加请求头 :param cookie: 添加cookie :param should_prevent: 实验性功能!压测过程中是否阻止休眠,此参数为true时,需要使用管理员权限运行才有效果,使用此功能会增加电脑功耗,但在无人值守时会非常有用 :param assert_options: 断言,传入一个字典列表,key必须包含两个:jsonpath和reference_object e.g. [{"jsonpath": "$.code", "reference_object": 429}, {"jsonpath": "$.code", "reference_object": "300"}], 也可以使用本包中的assert_option方法生成option :return: Dict """
使用assert_options时,要传入一个字典,但是如果感觉这个字典比较难以记忆的话,可以使用本包中的assert_option方法返回这个字典
async def run(): print("开始压测") result = await atomic_bomb_engine.run_async( url="https://xxxxx.xxx", method="GET", test_duration_secs=60, concurrent_requests=200, timeout_secs=10, verbose=False, should_prevent=True, assert_options=[ atomic_bomb_engine.assert_option("$.code", 429), atomic_bomb_engine.assert_option("$.code", 200) ]) print(result)
jsonpath如果不会用的话,建议去jsonpath学习
- 单接口压测结果实时监听 可以迭代包中的StatusListenIter类进行压测结果的监听
async def listen(): iterator = atomic_bomb_engine.StatusListenIter() for message in iterator: if message: print(message) else: await asyncio.sleep(0.3)
在这个循环中,你可以做落库等各种操作,不再赘述
- 压测时同时监听可以这样使用
async def main(): await asyncio.gather( run(), listen(), ) if __name__ == "__main__": asyncio.run(main())
- 多接口压测
多接口压测可以使用batch_async方法进行操作,函数签名和解释如下
async def batch_async(
test_duration_secs: int,
concurrent_requests: int,
api_endpoints:List[Dict],
verbose:bool=False,
should_prevent:bool=False) ->Dict:
"""
批量压测
:param test_duration_secs: 测试持续时间
:param concurrent_requests: 并发数
:param api_endpoints: 接口信息
:param verbose: 打印详细信息
:param should_prevent: 是否禁用睡眠
"""
同样的本包中也包含了一个对api_endpoint的包装:endpoint方法,方便调用,endpoint中的assert_options中也可以套用assert_option方法
async def run_batch():
result = await atomic_bomb_engine.batch_async(
test_duration_secs=10,
concurrent_requests=10,
api_endpoints=[
atomic_bomb_engine.endpoint(
name="test1",
url="https:xxxxx1.xx",
method="get",
weight=1,
timeout_secs=10,
assert_options=[atomic_bomb_engine.assert_option(jsonpath="$.code", reference_object=200)]
),
atomic_bomb_engine.endpoint(
name="test2",
url="https://xxxxx2.xx",
method="get",
weight=1,
timeout_secs=10)
])
print(result)
监听时可以使用BatchListenIter生成器
async def listen_batch():
iterator = atomic_bomb_engine.BatchListenIter()
for message in iterator:
if message:
print(message)
else:
await asyncio.sleep(0.3)
同时调用时同单接口
async def main():
await asyncio.gather(
run_batch(),
listen_batch(),
)
if __name__ == "__main__":
asyncio.run(main())
bug和需求
- 如果发现了bug,把复现步骤一起写到Issus中哈
- 如果有需求也可以在Issues中讨论
- 本程序是本人业余时间开发,不太准备保证时效性,但是如果有时间,一定第一时间回复和修改bug
TODO
- 前端展示页面
- 接口关联
Metadata
Release files for atomic-bomb-engine-py 0.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 62.7 MB
Release files / atomic_bomb_engine_py-0.3.7-cp312-none-win_amd64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp312-none-win_amd64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
c2f86a2c4e3dbad198899d22338ade58acc2f844fc6da1df8cbeede19163def7
|
|
BLAKE2b-256 checksum How to use checksums |
7f5f9830203a9b8f8ef9715d45e54a2c27094cf4e8dbecc05f0a71b8e968a292
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
a9707938681ac449f59e397c5ec46c8fcac22d2f3deea569353573b3ef9d483d
|
|
BLAKE2b-256 checksum How to use checksums |
86c930ecc89bdaed5bec461b3d79b2fb7ad0bbf49f91a2a1bdae70dc5bcd5d6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
cf136612b55e0b1446be1bd95bec96ea6f2bb201c9819300359bdb1960da68d1
|
|
BLAKE2b-256 checksum How to use checksums |
237e694363a9679e04ef9dfa5b92e90295e868abce6cce7daad3a5bc2593b3df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp312-cp312-macosx_10_12_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp312-cp312-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.12 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
008bed37406a2d2a67fd9de7771ad2209b810bb40cb02f33f6d9d59a3518786d
|
|
BLAKE2b-256 checksum How to use checksums |
e90e553372f22def36e7c18025742b61be6f305335041bc051f2bf10eabe46d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp311-none-win_amd64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp311-none-win_amd64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e665e7b8ecefed13ee7f16479a62c3b8590fd480a0c97ac26cbce5e370e3ff2d
|
|
BLAKE2b-256 checksum How to use checksums |
6ba3921af87e25b0ad10a477b55d7404b7bd533608a5eba083e898ab481e7642
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp311-cp311-manylinux_2_34_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp311-cp311-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
708326a5ff9f20ddfa20d51c576c4d4563c904056d16f57db888a8be706a23b1
|
|
BLAKE2b-256 checksum How to use checksums |
7781444c6e8be0bda847dcd2c684144d50491e434c6c8f312d6b92083899945c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7320f6d3298eb5ea5e3d9a90fb12b16c2f5bbe14fb6289022199a2b277874470
|
|
BLAKE2b-256 checksum How to use checksums |
4c278e3d7c2aaf48f0d4999b5b53f1a1f63110817cf6ae8496fa8d12ef2868c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp311-cp311-macosx_10_12_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp311-cp311-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.11 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
fcd498eaa0144dec0a541c6575e0eb70ff685b8678f29dc856bf9fb82cbcc89b
|
|
BLAKE2b-256 checksum How to use checksums |
78b67d85231ebd70001884fefc7b5430341ac50ee69107f98732b8c71c129c74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp310-none-win_amd64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp310-none-win_amd64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3b63e8a6a5db2a767461826c024db843bdeb760551d64fa8c521ba4ca919ac14
|
|
BLAKE2b-256 checksum How to use checksums |
59a93d48502b9d999307116961873c66bd2d785db7a710fc739fb3fa57982423
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp310-cp310-manylinux_2_34_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp310-cp310-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.10 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
b430dfd786be84760f774eec1aabce432324d98e2c0454c46270afaebc27014d
|
|
BLAKE2b-256 checksum How to use checksums |
b1ae5db1914147697f636ad5e52d0e09cebea523c5c2346eb9298c964900f05b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4b1294d8e3a266fd16c28efaa7990f0c54d9fbf9f2f32817e203e5e2d99e0b02
|
|
BLAKE2b-256 checksum How to use checksums |
dc8178e08e34314dbc48c28fd13b095ce454b0b231f047c03b042251184616f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp310-cp310-macosx_10_12_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp310-cp310-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.10 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
7db89ddcddb89d6c05ce88f8ef85965f43696738c37ea33aa48d32e882036e5c
|
|
BLAKE2b-256 checksum How to use checksums |
a15745f035662344c2cbf64902f86edf1200052a6218dbc6cabf7bf8dc6cc868
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp39-none-win_amd64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp39-none-win_amd64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6a911aa7de2565f59fe8bb6a613a402313328bc0231933a2455683b86fb26b8f
|
|
BLAKE2b-256 checksum How to use checksums |
776b11dd51ef664c9aeb8f9fa71930a8a10a7a471eef4a0ca00afa4bd092c112
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp39-cp39-manylinux_2_34_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp39-cp39-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.9 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
5b282df33c9f02769136876ebea2e6f61959ee42817a369c1f0408b4132a8998
|
|
BLAKE2b-256 checksum How to use checksums |
ba4a57c64ffa96c50a0c6cbe4d9ef2b094f9f6c5799c78cdac627f0bb4ca29d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp39-cp39-macosx_11_0_arm64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp39-cp39-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.9 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4f3e74b0b13bae4e9ab7626293a3039c3a2278feda734d5dcb08a7fe75f33053
|
|
BLAKE2b-256 checksum How to use checksums |
ac314d585b60f5162553436531dd2e356959810f94e0ea3c14bb7b84776f8772
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp39-cp39-macosx_10_12_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp39-cp39-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.9 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
4947b51cd546d4f8d500a5becdb679d0d8f47eaa6a51cacf0a76ce4bc3f0e2b3
|
|
BLAKE2b-256 checksum How to use checksums |
cd617405170c3055be9cd5a52e5d9159b85f986dbecbed871c8e9587c8a675a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp38-none-win_amd64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp38-none-win_amd64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
73db31c247a6d2ab94b97fe1afd4a450c66c6b488e10ef52bd61e031ca9476a1
|
|
BLAKE2b-256 checksum How to use checksums |
debeccbab4961f5aa61248bafca424f99e615f5c153100ca240d38c7ccf1b0ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp38-cp38-manylinux_2_34_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp38-cp38-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.8 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
e0eb39a1f2e0e903ac3524bb171f0656cbf9f724b7e01128ab1f2a58256d5d28
|
|
BLAKE2b-256 checksum How to use checksums |
5e8a91c2e2f91f07618af34d4b3a71af94d2f19ac4948e9561ee943ba0e00fcc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp38-cp38-macosx_11_0_arm64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp38-cp38-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.8 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
60cb876aa263e57850a1226aa644f6a8519e87796dc27e03587ebd97e5191123
|
|
BLAKE2b-256 checksum How to use checksums |
e3ac4a8908d998e11caab488951a40e0d18cd04b3974808b92f37af119239eb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|
Release files / atomic_bomb_engine_py-0.3.7-cp38-cp38-macosx_10_12_x86_64.whl
| Download URL | atomic_bomb_engine_py-0.3.7-cp38-cp38-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.8 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
451dc4919f66d55f9ccd2c692bf4c85dfd5bed9d7f5d32ab8b07eb1e0e061612
|
|
BLAKE2b-256 checksum How to use checksums |
189dc00b2f3ceed5990a695299be9ad171b2b1949f49734fe660a815fb4ec415
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.2
|