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

Uploaded CPython 3.12Windows x86-64

atomic_bomb_engine_py-0.3.7-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.7-cp312-cp312-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.7-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.7-cp311-none-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.11Windows x86-64

atomic_bomb_engine_py-0.3.7-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.7-cp311-cp311-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.7-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.7-cp310-none-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.10Windows x86-64

atomic_bomb_engine_py-0.3.7-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.7-cp310-cp310-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.7-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.7-cp39-none-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.9Windows x86-64

atomic_bomb_engine_py-0.3.7-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.7-cp39-cp39-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.7-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.7-cp38-none-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.8Windows x86-64

atomic_bomb_engine_py-0.3.7-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.7-cp38-cp38-macosx_11_0_arm64.whl (1.9 MB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

atomic_bomb_engine_py-0.3.7-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.7-cp312-none-win_amd64.whl.

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 c2f86a2c4e3dbad198899d22338ade58acc2f844fc6da1df8cbeede19163def7
MD5 15194c3580b9bfbff8fd8f96cce76088
BLAKE2b-256 7f5f9830203a9b8f8ef9715d45e54a2c27094cf4e8dbecc05f0a71b8e968a292

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a9707938681ac449f59e397c5ec46c8fcac22d2f3deea569353573b3ef9d483d
MD5 b0977cc6821fa9c85a461cc5d1f7a562
BLAKE2b-256 86c930ecc89bdaed5bec461b3d79b2fb7ad0bbf49f91a2a1bdae70dc5bcd5d6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cf136612b55e0b1446be1bd95bec96ea6f2bb201c9819300359bdb1960da68d1
MD5 a974c59b4aec750cbd7cae3a93ca8ef7
BLAKE2b-256 237e694363a9679e04ef9dfa5b92e90295e868abce6cce7daad3a5bc2593b3df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 008bed37406a2d2a67fd9de7771ad2209b810bb40cb02f33f6d9d59a3518786d
MD5 29f6fc7c0a56191817e987a00debe95f
BLAKE2b-256 e90e553372f22def36e7c18025742b61be6f305335041bc051f2bf10eabe46d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 e665e7b8ecefed13ee7f16479a62c3b8590fd480a0c97ac26cbce5e370e3ff2d
MD5 357ee164b129df11905b70c6a0149c20
BLAKE2b-256 6ba3921af87e25b0ad10a477b55d7404b7bd533608a5eba083e898ab481e7642

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 708326a5ff9f20ddfa20d51c576c4d4563c904056d16f57db888a8be706a23b1
MD5 047ccf0491c9fe28c0ca1fb85be3477b
BLAKE2b-256 7781444c6e8be0bda847dcd2c684144d50491e434c6c8f312d6b92083899945c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7320f6d3298eb5ea5e3d9a90fb12b16c2f5bbe14fb6289022199a2b277874470
MD5 acd365cde206e5d63f4ff6200e3fc553
BLAKE2b-256 4c278e3d7c2aaf48f0d4999b5b53f1a1f63110817cf6ae8496fa8d12ef2868c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fcd498eaa0144dec0a541c6575e0eb70ff685b8678f29dc856bf9fb82cbcc89b
MD5 ef57cd7e627d0d9ec46e5fa74851619a
BLAKE2b-256 78b67d85231ebd70001884fefc7b5430341ac50ee69107f98732b8c71c129c74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 3b63e8a6a5db2a767461826c024db843bdeb760551d64fa8c521ba4ca919ac14
MD5 42aec5fd4da84b8bc3721443c445f50a
BLAKE2b-256 59a93d48502b9d999307116961873c66bd2d785db7a710fc739fb3fa57982423

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b430dfd786be84760f774eec1aabce432324d98e2c0454c46270afaebc27014d
MD5 508cd399fdf250fd3f57b5bd3d1d6111
BLAKE2b-256 b1ae5db1914147697f636ad5e52d0e09cebea523c5c2346eb9298c964900f05b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4b1294d8e3a266fd16c28efaa7990f0c54d9fbf9f2f32817e203e5e2d99e0b02
MD5 a41f52a59efd35075cb1731b3f41107b
BLAKE2b-256 dc8178e08e34314dbc48c28fd13b095ce454b0b231f047c03b042251184616f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7db89ddcddb89d6c05ce88f8ef85965f43696738c37ea33aa48d32e882036e5c
MD5 2c37b9c64a97e4710e0a1e5852c6178c
BLAKE2b-256 a15745f035662344c2cbf64902f86edf1200052a6218dbc6cabf7bf8dc6cc868

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 6a911aa7de2565f59fe8bb6a613a402313328bc0231933a2455683b86fb26b8f
MD5 8939efddbb93dbbcba81510702daed46
BLAKE2b-256 776b11dd51ef664c9aeb8f9fa71930a8a10a7a471eef4a0ca00afa4bd092c112

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 5b282df33c9f02769136876ebea2e6f61959ee42817a369c1f0408b4132a8998
MD5 39950eb14103a8e5277fdb0124d9bcfc
BLAKE2b-256 ba4a57c64ffa96c50a0c6cbe4d9ef2b094f9f6c5799c78cdac627f0bb4ca29d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f3e74b0b13bae4e9ab7626293a3039c3a2278feda734d5dcb08a7fe75f33053
MD5 cba28aa6ee3cc09f4a403ca1dae3a61e
BLAKE2b-256 ac314d585b60f5162553436531dd2e356959810f94e0ea3c14bb7b84776f8772

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4947b51cd546d4f8d500a5becdb679d0d8f47eaa6a51cacf0a76ce4bc3f0e2b3
MD5 c2f61acc8b8fe5f0d0b213cdb78ba2a1
BLAKE2b-256 cd617405170c3055be9cd5a52e5d9159b85f986dbecbed871c8e9587c8a675a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 73db31c247a6d2ab94b97fe1afd4a450c66c6b488e10ef52bd61e031ca9476a1
MD5 9ab785eee6ad06d3fc177730295da924
BLAKE2b-256 debeccbab4961f5aa61248bafca424f99e615f5c153100ca240d38c7ccf1b0ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e0eb39a1f2e0e903ac3524bb171f0656cbf9f724b7e01128ab1f2a58256d5d28
MD5 6c3e4c7cbf9135114af7221e646287f4
BLAKE2b-256 5e8a91c2e2f91f07618af34d4b3a71af94d2f19ac4948e9561ee943ba0e00fcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 60cb876aa263e57850a1226aa644f6a8519e87796dc27e03587ebd97e5191123
MD5 001c9ad5ea7a2ffc4ff8843f47107903
BLAKE2b-256 e3ac4a8908d998e11caab488951a40e0d18cd04b3974808b92f37af119239eb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.7-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 451dc4919f66d55f9ccd2c692bf4c85dfd5bed9d7f5d32ab8b07eb1e0e061612
MD5 1fd447dda477af35ae0ee3ac9fdd71d8
BLAKE2b-256 189dc00b2f3ceed5990a695299be9ad171b2b1949f49734fe660a815fb4ec415

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