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.6-cp312-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.12Windows x86-64

atomic_bomb_engine_py-0.3.6-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.6-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.6-cp312-cp312-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

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

Uploaded CPython 3.11Windows x86-64

atomic_bomb_engine_py-0.3.6-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.6-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.6-cp311-cp311-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

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

Uploaded CPython 3.10Windows x86-64

atomic_bomb_engine_py-0.3.6-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.6-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.6-cp310-cp310-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

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

Uploaded CPython 3.9Windows x86-64

atomic_bomb_engine_py-0.3.6-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.6-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.6-cp39-cp39-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.9macOS 10.12+ x86-64

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

Uploaded CPython 3.8Windows x86-64

atomic_bomb_engine_py-0.3.6-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.6-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.6-cp38-cp38-macosx_10_12_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.8macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 0a6fa25ac40052546107f70a01ef27c716f2ca45faa7801de2f2ebf5c169c856
MD5 cc068a031159762d186f5f572199c1cd
BLAKE2b-256 fdf310b749bc106491f19271df2b0b42c2f63cdfc19145477c3fc767bb34068e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2b0aedc69649c3e94cebd079db2e8d5bebed2fdb32e1d53a9186343ab26c8603
MD5 2ca9a3ca35928718ed7927335f67704c
BLAKE2b-256 ff3bfe34cb7d1d0a7c7cb60fee89782589c14d6ba0ffddcb2de7c0f14c96f46c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f966d3fa1458c9ba65516090535e15ae35eeda4614f3dc9a0e70366d48898b5
MD5 16f3293e9b5d93ec8c4a878c7bfbdf24
BLAKE2b-256 e63708f71b89739ccb9bbd5deaff539052d30d29b1c5f14a3530083f6452b92f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0d67184a5e03bf79e49a067118219268e1c3203ecb286ec17faf0b9939cb944c
MD5 7ecea8880d30d72508920c37c197320a
BLAKE2b-256 463309ea533773521767404eab47271bfb8ea6c1cdfd2b2994835b32e404c78b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 bd44a47ebf9e2c9ad502a8df8919dc45f25b521523e432a21f0a2e816ef2bdff
MD5 780317164dd0bc53a10f09bf421f1cce
BLAKE2b-256 632090fb26d62abe7c85859a198f67b9ea2229062a2bf16dd4c07c5d18772d76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ad45edbccea56946379a7f460861328bd9f35a4567a153dfee23940830bffaeb
MD5 87860c64b9366ccebd7777538c80d82d
BLAKE2b-256 18ea2d1843fff30ba4169e8d2b19185c66273e807bdebc80e30c79116f07a1dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20baf800ee51394164c285fef419cd799dc16cfea4a7436074db299a672ac2f2
MD5 d9ef3f1311b51952694d08bb25fee924
BLAKE2b-256 65d9ed7f179eb899bb9467b23a8b5ff0acf2f3b376068bd34a3d0aeea41aa5b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8c991d7958d021cfbe3538536112de33d2f7864409feb57ef71d6f0869aab1ed
MD5 3b89006d78614cb44cf89e02b601137b
BLAKE2b-256 811ec48c29597c6612d103d7e1a79ac8e0c50abbcb85fc37a246dd86a43c97a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 08c8970bb9d8751a8d128d6d8bfe2344e37033b9305e585434796c5f28b56b39
MD5 10cd0db69f7ebb3beb42008ceb8d8312
BLAKE2b-256 b5954db461692f01db40ec72573b87e70ac66d993f0cc755f6797afc33c8842b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 84bd10d90a5b94c502c3195e20ed993ec478626b5656daf37b16e65289ee0f33
MD5 aa3e648728a92b1bec486e7006acd494
BLAKE2b-256 73105ee7cfe0a724374be96d4add8aa36682741e4f812a5835c33a51a54120fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb4f3da15c0d26be17f39bf100d9ee694fa3cc01df300f08bd0ed307a72d6e3d
MD5 b779824711d63a09a478bf9831b41945
BLAKE2b-256 9499beb1a7037070e3f126c51394a11a6d5e006d043e0cd1014fb27516339510

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 15ba6fbdb50cf73075cb912fd27b91dcd3f48226f78db65db42115212a874aba
MD5 2153dfb7592f6da5d83dcb8e78a94bc7
BLAKE2b-256 d5197f38a9b026f57beb6d8a44e195e5c325ef80d49eb8b2592fbc5f1c9100ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 6f63641e15e9271bb5f94de3c9598934925ff02db5e0a9ad0ec2ca1ae9ea4e6a
MD5 cf6a68a68f45dd8f1d120b015cd0e75e
BLAKE2b-256 c3cdd1157ee01ffd3e958975eedcd2436da4e6d0f5dd3666776aed2a638422f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3e4f57416757826a3df0828f36d359c6c7d700a7ea5e6301e46a4ebf884a5ee9
MD5 d75a5e12f188f2bfa60c1faacfc7557c
BLAKE2b-256 a524f79a781707e49072fb4c544a10605a70ddbbaed9e432967b6b0100f3d6ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5794ce702790aae150a0f0c94016f7470a86ef411aa5491030635b266597c332
MD5 12aa3146e205b3ade63a748289b97575
BLAKE2b-256 17d11cf8d30ea8d230146e8d87e7d41b72ff3e0eb3f791262574de25eb2a7fff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1648ea6b431f315a504ae05db1dc184e4cfb068b99ed9514904814f91e62ea58
MD5 4e829d37bccf422c0cf13f75771aa396
BLAKE2b-256 d9181669b1b2ec89741194a8f201016e77b0c6fc013b788a530d481cc392d2c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 53dbc42a54722df33bf3dcc20a0e7b0ac15a1789a4b2be199127fd9076f41547
MD5 cff8b5a7dcc1c4eac6e064b9ef42c748
BLAKE2b-256 86183a8cbf7cd4addc30a5422b2eb2f9129d9f42f6d9db1190bfff88eea60b64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0c7188d1e6bf1cb888277416b769256d886ee49d8201a5c263003b5f1d947379
MD5 88faba7f3dda7a3b8b27571b8f3ea72f
BLAKE2b-256 8bf223a14cd0a05da28ddd440310e946b355e0b496dc9f61667efc0a2f40d722

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 06a0b2860d4fa2c08c8fc47d9a59655c8fdda4bbd4e1b56f866f4eb0e35bfdeb
MD5 7a9c59043a0e0ed6a23f5a22a8a9043e
BLAKE2b-256 8fc1d83244fc69dfe74f0d3ac2a3376c3a806825481332be41d9539cc3cafab5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.6-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4496b6f94a6812ab428d451f11887dcb0d21b372e458507aac58e7de561be7e7
MD5 e263bb6768a2eef018b16029264e1b7d
BLAKE2b-256 648ce1d532bc4a8ed16f9f861e82b8da191d6c722d7efe76fcfd085f5a920ea0

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