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

Uploaded CPython 3.12Windows x86-64

atomic_bomb_engine_py-0.3.5-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.5-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.5-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.5-cp311-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.11Windows x86-64

atomic_bomb_engine_py-0.3.5-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.5-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.5-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.5-cp310-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.10Windows x86-64

atomic_bomb_engine_py-0.3.5-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.5-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.5-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.5-cp39-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.9Windows x86-64

atomic_bomb_engine_py-0.3.5-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.5-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.5-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.5-cp38-none-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.8Windows x86-64

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 13fb60050c815a1df3fce8b307af82358094f104f4449d376d6f430a6f821550
MD5 a2e3cd7306914d9f70adfce925c577fc
BLAKE2b-256 954470fb209f71778ef759720916f32a7c1d7e84c22df51d6aa94c1d4edcdcfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 86d97bba282b4f0a5ee7aaaecafdd25a2e372747173ab04a9660c2135a924f04
MD5 1da2a86f3f43ae999f9244059ce9b127
BLAKE2b-256 938655548a3a899f953bdac96378c4779dfbb530a0e7e8857c746ceaaf123aeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6a54abde017ad522a397893b5be3fae10c6dbd3b109377476ed832c827d4a7a
MD5 aa3e400cd2987aed0108a094a2a3cf9b
BLAKE2b-256 1ef092367f1fe7a93d9d91b897905289b6b4319f5e3661a8a4e8116d265cf3d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8befcb6a5b1f7c5cfdbd4072e4fe2c7fe7db05068a39ffc5272fca2dd7fef139
MD5 7ff3c6efee50b31052d867ddd92a8aab
BLAKE2b-256 e0bbf002b0cbf2413b3aa7733ecc45105a651fde482b30929df95ef72fbb3007

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 1116b1169ee9eb0f597ec9199e50c91f371ac071b621e8feb575d622189821a3
MD5 3fb26553fa84c2669a8c168bac185a0f
BLAKE2b-256 2b400b1cf9b717f2b44a9354855e930aedacb216a606e96820c23c418a62efb5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 6d0cc34145b92f2e70fca1b5e1e4b4ef951134726ac36f8819414f32e7dade12
MD5 b6ceb0cdd45b11e402c6a482bbfed3e8
BLAKE2b-256 64cad47d06913270e19ba507baec296693747a0f466a38be161f8725d634869e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2bf35280072306bb5a8cf5a51048f3f61b1eb6bd0bf031f09f4e472a77914204
MD5 d289a7a7e3039fe0a9f8639d45b1e033
BLAKE2b-256 ab3a60e4bdd05c7530f7b5cffef514aa9349a789fb9cd10652f7823483e8726f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3147452d1223f7c640dfe080ad4fd11f71ecdf43f733580b52a5de6d5f7da4b5
MD5 dcb477e198ef18faaec105bddc6cc534
BLAKE2b-256 d573173048d499072403bfb5dd96f36993726af1faeae603e175915f51aac7af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 3e629ba4dcdfe0efbf5fdef5a115044de50664e14946256db8942a6acab446d8
MD5 16b5e252fc25b00c4f9561a8e362e780
BLAKE2b-256 9807f79c76a8d344c92e20e9b126f85053f53440e4d65bf54aaeedeeb69257e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 daff55df73abdf61808b2b596cc971d994c72417ed244b40c32bddf8eab49ada
MD5 a8505384400ac5030a5788ff8261a394
BLAKE2b-256 057738588098fcee5fce5246d79cdd44e5a3cce39d3acf948ba48589ce673289

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ecb72a9f772daa12cd2a7ff6a4a1dcdf7e26eced05d2897c31c4f5f5ef662cb6
MD5 30007a9c9fb6140504cb0f12ab3158af
BLAKE2b-256 31264b378670ebc2bbca4747ddc95545982b067f0593e1236b814d5ffa48983e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a5e6ffe41416da9fd969307804afe1766cd4963dbf629001b4d5909c444a3f04
MD5 85bf4262ea26aa48f7ed87e1edbdd4d5
BLAKE2b-256 3c5c8631f828047952e9c40fac007025786a2a7ccb3925369345f3a2b3aaa338

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 c0bfef2a9b25b72db48efe4dc206a19fa9e96182cd9f495c5e877e3b2d0ec72e
MD5 26910e7decd444cdd45ab96af5f7437b
BLAKE2b-256 043907513e901558075d22eb03b65c33a1d66aa35c15c28114bd69303c4799e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 76f2d9b961b458e70e6c0ae08af425b0ef53a4cb87184cfcc107dfd4e15cdd97
MD5 765b923b6af50e6e40ed72ccbee3f38a
BLAKE2b-256 2d96402cbbc42b10c42974bc1ba085e9e74fb5aa0fcb2443c5a326715cb9e4d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e2e7a754942c0992742b70f4d7e5f09819c6a68630997c2b52c9b4a85080c511
MD5 d6be904881d1a71c06ef347fcb98e15c
BLAKE2b-256 d83a6fe98dcf9ff59774c16207176ba7e61a75f1618f29d90f04cc1b844f1633

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cfd2da721f288bc90d36d1ae4919215d036a905a5d002e77de6a37af50ce0c1a
MD5 d586c79d1e196b2cd2c219a95ddae16c
BLAKE2b-256 709ad6eef72b68880ebf12f558f078e73a3637044caecbc9a3e65108f687ee35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 05531d1ff58e4b1161684be8941e67809b9c2a2138bc443ae6224c85e114b6f3
MD5 eb2208a846b2a708a9de88f071a7863d
BLAKE2b-256 3a536082af277c725467a494d6ff7deae857fd8d9cb9b5284a0af70c9dcb6bb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 7355902d81e8eebcd3b0cc7b009fb711c98aaf4a2dea28365a12b3340d13631c
MD5 7550449232772b1434d427bf19bd3ccc
BLAKE2b-256 942937e29b0be6748efecd8201b3689cb728e646147c0bc37587a4806b14cf01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83cdcc7d09f7f821df29c0eb81a7a2598b137bed478cbafa8b452ade759455ca
MD5 176ab68a1d40263c8c7fc5c408a24f99
BLAKE2b-256 dec348d54f326b9eb0574d99a0a5d6c9ba0966a51d4474bb771d6e900ee23cd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.5-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 374a137412d7498dd5f687b5bdf2beec7e9be3ce636d7215f9d8a640f9b6cd11
MD5 e20427c432e060af9aef64708d700c6a
BLAKE2b-256 7dc5fbcb3ed44e73a96c0ffef59812f7cb0d90fd9d128a579ac49e6384ef3737

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