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(esult)
    

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.8Windows x86-64

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 08aa19d10d86a1c9bab773e128fe7825052fa6ff5966ff1a9e7b6389154c05e1
MD5 183085b2af57cd383464c1551bdaf21e
BLAKE2b-256 2508a67fd2c02cf3d240e6fa5dcdfb3de62ee01b2dcd7f16980e1549e48ead47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 47a3ddedb2bd80c47c81c4518e8fc7ccaed860df87c1ed388f826d103db327b7
MD5 730af1f6a0d99b2e9f42de832cfa30bf
BLAKE2b-256 f01731dee9ad49726118534561a7b95ff19a34f06a2bc6ee7cb76919fadb9447

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 385d931cf4c0f83565eab7d971ba308ac12bf3e4eb6da1c767529b835c6a1193
MD5 3a7fc9bf31fb0aa3c074473714b69271
BLAKE2b-256 05d8d651019595ee451b593d2eaafbc7426329f4f054b3a923f8edb32ab5b1c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a2b0359d0855a5ec1468019f7b1abc5e8db04215ea55c1960bb255e410eecd8d
MD5 20661841cf92764ed05028770f3726f6
BLAKE2b-256 cc7fba8b0880694d2c0d4cdf76fc7583d5725a83203f084374242d9aa5d8d37a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 7912c7631c175b592fc33e6ad93e37f728a5ba94252d8ca1a2b537f71bccdfd0
MD5 3e5ed75f6fcda6391f38b68e68805ce3
BLAKE2b-256 51dcb91d52af44c4b3d94d4182a717f5aa610c21a63c7d7a8b8321fe248477fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dea9d9515f621bd37297482db743bc93289499abbbe5365bac7f8f0b74ccf34c
MD5 7709b41bf5cb88e2ae4b88fca56db8b9
BLAKE2b-256 20707be32708fc9c790d63d252578a81dba18345de165bf00e7adbd4b3dbeb9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20d9445b350feacf0f74870f3a0dec1ea9dcac1f1b54b29e3e05c0bd9de9c02f
MD5 3726792fcab8e72914c4b40fb3775f18
BLAKE2b-256 25d9a35437053496cabc1115f75d538c624419c11fcc76b2cc698ac272f0efc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5a579e5eb8341b868a2170949fb29c845c9b065b18ccdaf9b6af77802f3a9b8e
MD5 874b8ac77c6318c62416d320327dadd8
BLAKE2b-256 133500d9cadacda5bee001ee87062448985d59c2206d532a6181ccc7cf925de3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 fb2b604b201fc2c524d47a2dc2e643df64b8631210b4527757f083d0ed18a4f4
MD5 261d37b45e1e29f28ac84efac2789f42
BLAKE2b-256 59eacc09bd2b30a51182e0b95a2b21175ce2bc0824ebe3d369c852c014181e31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8cba7ec81bb6ccb97c0cfab1df31a8b245a3c32b712d9097a3d789baa2a949b3
MD5 c37a54ba44ac1da1ded9437767e1e736
BLAKE2b-256 570915aaa01fc31aef510b009c1de7ae9710f144f064ad2950e031739d026c9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 40f5b7cf48e905a9f5212e9259431f3b828f3bd369c99e5801a80890399a2966
MD5 7320574cafd6696c0831c0ceef6a2389
BLAKE2b-256 33b3fce7594e4827fe0d4f910c408c78165c4c3a657e5a5e6589fec2fe3f2125

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a15759e0ed3271af9b750506596ed12f350b37aa05fe062d878f8d01daaa2607
MD5 bb8987e72f03032516a935965ff95453
BLAKE2b-256 97366697e793dbf1f99fb0112ad9223a30ddd06d99511efaae2a175719651f82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 a33aacee11ffe9fef436a0b890e1726fc282c7231a56e8f669cdf7253ed5b880
MD5 ca9d6909e227e52106a4f2f68af2fcdd
BLAKE2b-256 3c055f28b849c596289602a619495ab7d4374227cc4ea423ef834cc9a106e71c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e96dc97b9aa5fdd2d2dc4a3677d22cee977a3faa15c4a35ed0a96d9711e4890b
MD5 00097d2928cb460c88f8f017a2379517
BLAKE2b-256 b9ba1f7a87c2c7340ab4220afd66ff80b2520b775ebc628e291323e4071f464f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e02551837cf908b592bfa609d8ba954895652cf2d7722fd1729a8ae07948ad86
MD5 8eaaca3a86084a76b1c4a973607c6095
BLAKE2b-256 64fa951708ca47c5aeb845984fd71daf4613c8e5039f9d7e51d85e9696a6ab90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 49347485b28d477087b6f1fcd35a15c207906e153d61c04abdf7bb3170fb56cd
MD5 3cc72a7469731177006604993a9bd2c1
BLAKE2b-256 4e17b2cc565e253a8b902bd0ac11daa828a428d4d672ac2e50c727b366a597d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 7bb9758b6e646afb76805266fddf527a5156d9d65264ab289a89a9b63a98e690
MD5 82202ff50a75c6741a7d306c951ea090
BLAKE2b-256 d3b50426663055cc0f1d81a775594579ec15f0c09832d78a2662c988a52f9391

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f1ae94973a47a8d2141bda0544b94e50037bbee709f1e22ce78d96069834ed2c
MD5 c5d831b7eb2a33aa554c13f1fd2d2288
BLAKE2b-256 8a6844e449985ab7373341f80c8a4b1087d9f024eac9b675365c43343a75da90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a265a464cc61092d5b276174dd6ac031599c349884ea416111f469a2a2299cc9
MD5 6690928a5f17c83a029f396c3409ea8d
BLAKE2b-256 797e7bd10d5530c5301a4bc723365953eacfa328a3c25b93494f5d80b31b4b6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.1-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 88f5bda2096cdc971466e754bfc4008be7450c9f9ed86e731c45dedf64d4ccba
MD5 fb6c9b8c3894177c6ef4a958f7ce781a
BLAKE2b-256 20dc42b6d213d2482f602ea19cc1833081a2681dfc0a605ddf62a85f35aaa269

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