Skip to main content

No project description provided

Project description

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

  • 前端展示页面
  • 接口关联

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

atomic_bomb_engine_py-0.3.4-cp312-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.12Windows x86-64

atomic_bomb_engine_py-0.3.4-cp312-cp312-manylinux_2_34_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

atomic_bomb_engine_py-0.3.4-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

atomic_bomb_engine_py-0.3.4-cp311-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.11Windows x86-64

atomic_bomb_engine_py-0.3.4-cp311-cp311-manylinux_2_34_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

atomic_bomb_engine_py-0.3.4-cp311-cp311-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.4-cp311-cp311-macosx_10_12_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

atomic_bomb_engine_py-0.3.4-cp310-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10Windows x86-64

atomic_bomb_engine_py-0.3.4-cp310-cp310-manylinux_2_34_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

atomic_bomb_engine_py-0.3.4-cp310-cp310-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.4-cp310-cp310-macosx_10_12_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

atomic_bomb_engine_py-0.3.4-cp39-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.9Windows x86-64

atomic_bomb_engine_py-0.3.4-cp39-cp39-manylinux_2_34_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

atomic_bomb_engine_py-0.3.4-cp39-cp39-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.4-cp39-cp39-macosx_10_12_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9macOS 10.12+ x86-64

atomic_bomb_engine_py-0.3.4-cp38-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.8Windows x86-64

atomic_bomb_engine_py-0.3.4-cp38-cp38-manylinux_2_34_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

atomic_bomb_engine_py-0.3.4-cp38-cp38-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.4-cp38-cp38-macosx_10_12_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.8macOS 10.12+ x86-64

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 79526778bd7a5fe794b8245f9c8025ea1dcfcaddd614c818710dfd1d30ed2c52
MD5 03c879e2928d25490450eba6a7ce8ac4
BLAKE2b-256 fc8f27625c98a7ba99d7ec6971e65799e1913b3c6aa0642df71756a2502dc2aa

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a2ab114e165c726e5dc2466457d63344e754048363e1e203e9e28925f3db0daa
MD5 c8727f7cbdbcf288e11e52fc6209a9d1
BLAKE2b-256 78cdc85b44aa29bb62f4b61f43ea5e2ab697c8b87af89aba62a5a85b1e7e0b6d

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5ca2ea5a9a4474e3a2d3080b9effc218c90a6656c0fd05448ff15cc740a3abf
MD5 930503fbc5bffce3228b15800e6fb9de
BLAKE2b-256 39562893907b88c99f5e4c37a1b72d0b15df3a3458ac9fb96367b84de82f879d

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d78bb48f8e360d2ba2e987308ac9a1fdd82c79dab1837f9aeb769726b382350c
MD5 4b8c70a54a1f459546e5158231e316a3
BLAKE2b-256 95d2bf4ac9b624ed07aabbe6cc7f8aee4a16396d29952fa7f5ef829c1adbe7ce

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 dffb6db3597ce9bbeab2e8533a4e928267786af84531efad46d6688b521651ef
MD5 70bfd67330827809dbc78af68a78a585
BLAKE2b-256 c238cad142b88a9c298b8732a9a609a30bdb8e61eb4c8f449b479f3627f87018

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5d6a34cac54d341a1d5e942ad43270dd428e94aea9a5f5b163bb251b73f0f241
MD5 daadf58c31c158503336fb949d3b0d7d
BLAKE2b-256 d43b8b8912c8dcfa0270c8f0360451c585a75884df1ff6df674fda5ba95fdc90

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a28a8fa28e8bef1f50e2da2a243f97e1b54a968c1cefa6ba3a0bf152a9cd661f
MD5 dca79c62dcc8dce54547a97b52a51fa8
BLAKE2b-256 edebc78feb5ec983fdcd60e656cd7bffe79a1622d5c80977a7e63cd4344e75dc

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 24b52a884a4bf10b19774a734f3c42dc95635e91d672667caa37f3212d58dc54
MD5 a3d3c4f155387992d5b64339cdcbe16d
BLAKE2b-256 dd6dd04e2cce4f32f288687652b7eea3fcfec8220f173cc37a37b15073f0e15f

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp310-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 5654efb5d30216005df98cac37f6d8a8c449f71cef662e08db534e5e3609c483
MD5 7ca06c6495c6a230eddc2204415b9320
BLAKE2b-256 0c1cf97da643f17b0c92a6363943ca9051c15cda49343f6a7e44e22aa4dc89c2

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0176ed5bb67130b58de8cbd52b527371b2ed0be784510719710eacf89872e497
MD5 d58da22cd838b8b603167cd490cba663
BLAKE2b-256 efd295fd654b974d02a5e3c56288ae8cd140a561f890a6c814c32fa573c43b52

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35e87a99ef87fd6ddd23d2a6c8a2c3aba733b77815432f6f661d56c244be03f9
MD5 d041cec0f46b63d03c86bc49d6b8f180
BLAKE2b-256 7a5dfd24df737d3ff8a510fb52ec03b88b3fef6006dcacfc9f24fc0dfa7eb143

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ef69448a40876296199b8463a3cab71d7a90f6fbe7d7b15ef6f5c49dc35968b7
MD5 93f14b2f1fb46e8d041a5f4aa7ba34e7
BLAKE2b-256 171f51354319416d5d68aab87d3eedc739a3806f93198f9010eeaf1cf5e013cc

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp39-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 f7c40f637a56e8498c5f74247e049d93be661b954f9775ea6f917c9de73a4d1e
MD5 2faa7aa6a6a14f1b9c439efefa35cb79
BLAKE2b-256 6112398789132aebce8d96904506b8bb003b0caffe99286ba74f91730a301052

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fb58903f1c9627cfba88bb1393b7c4a61b5794ff21ba4b2f7fd08ce52a708d14
MD5 4832be452e0ffe0ae62aa25a9f68becc
BLAKE2b-256 bed747c362d6fece4e4c2b1d9c4737d9c3c528c17c081213b31585ddd5ecdbe0

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a14c117a247abd987d700a39c882bd6b84c7c6c9903978ac80121f1824ad3d5
MD5 84ec97cb2393839dcb855afe5c132d3f
BLAKE2b-256 b0e9531051d62cdf78215e18a32e129460fd39d461f8aa4db8facd737d1a672e

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp39-cp39-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 31026de46814af19b2ae0d42f4e0183708e6e45764277eedbe07f33cc5d2b966
MD5 66f4104eb3c28801ba653bf30febd5a2
BLAKE2b-256 b81584ef4526e0727152014237739bb2abf63ad31669bb0342fd47279cc0645c

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp38-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 3ad53e4a3cb43e031c9a851ab9f8131ef3297fd9555048aa8d1568a374e0dde3
MD5 de9d0db62a996f78847f253d09b22a9c
BLAKE2b-256 2c612c4add2e0940d6c0a4bc5bdcbaf17ac2062a2a2cbfbd6f512e2c99796c1c

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 02f90306dd1748577ca0dc3c0a3896626ed0f3e6df0b1ced96d111fc896b3a60
MD5 1a9b2baaa214c1643f85372dd1ef160e
BLAKE2b-256 1b0b4d653eec670047fbdd3497154c7a0a365a260c8721b87bb398caa558166d

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6edac18f5d347ea0bb7f3b3c6722ae4c500d8650324d5d388a909dc12049c0b1
MD5 1e1a1fa27dce91f1984b40d85598eb5a
BLAKE2b-256 9d14870a0d12081f9a53b4ecdace932cb68a33960d8434ee5dd6f12444d8e412

See more details on using hashes here.

File details

Details for the file atomic_bomb_engine_py-0.3.4-cp38-cp38-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.4-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 25a3e34a8a1a49a125767a6a8b0d3e8c0e28aee56a296dc74d85aa282dd2d9bb
MD5 3a67f585ec538512a306209e5964905c
BLAKE2b-256 eb1bdc390f0d766aaf0cd8276ec11ff25c04e6ae2ac6246cbb8e218472331d54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page