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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.8Windows x86-64

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 27ff89bea81df42a3ebf313e7c48d8414432232e01f173bd0fd72e6484c38126
MD5 db7c43c0eeee13a1a769b057b0a99a1c
BLAKE2b-256 94ee958c22d0d8f31b8987cc1413e9a7af70778e4ee98c78054da6a93e949677

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1b04883e661165eaebac30abc02b29eeb251cdf743ba8dada088e0c4d06cf356
MD5 c7a8a05376632aba76b77a2b7b95d54e
BLAKE2b-256 a69a6472315b72e7072d1bb156148f0dcf80db01000d590ed26a9ffa4f4c1561

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6a764d2626e7b20e44161e3e7e627e27d59db16cc271796a6c9b6575ae351bd4
MD5 b340235d910b5c6e5af0fc02443b73e3
BLAKE2b-256 dd31a215b4530f75b7795b55349f72a8bfcee36f624d89a70411983ff6cec6fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ed2f946bcc1d0084bb09c33341553a87d2f01897557e126080293ce32a91f300
MD5 5eedadde59a98105b38b626d9873fb5e
BLAKE2b-256 66735f199df70eebb14bfb0698a0a231185a44c409931f0b5a7687571f647083

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 6d94eaa33c81b5159162e2198c9aaf633f85a97fb2c698531bfec26634fd3996
MD5 bd47c409209180a42c992d30a2edc893
BLAKE2b-256 a3d18a436204db015d8a89020fa2b86f854bad829a6ef163e613838d8d94b7be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8272425d0d1b36dd62a8aff7a7939c5f2774736ca295a78c9608d15b8efa640d
MD5 3c5de5670c980be32220c1da748a3735
BLAKE2b-256 4df2e542e94b25ce60926e71a82a9a731e39f33121bbf59ec2ad22c652fe53d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 936b8f96ee7457425258f5e03c093539a72544f1cb9b1efa3dcd76d215b1c390
MD5 f8585d60c582538bf6b57aba29d28bbf
BLAKE2b-256 81cf7aecd3d54d6b6665f5d4737af81378a23245acaaaceb0de063c14b87230e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1af68ed20518a569ff3a1ebc424493feb22d166bd30081871b040acb30492c9c
MD5 d1cbeeb5b6e3f9aa7e2c2fbc787a7566
BLAKE2b-256 ae6e73c434c993c80825c6eed502a780cf362a58a2a891fc3139153ccbef4d90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 22c62139539a1b1712c7e24e0f12bdc0e4662a0893a588e0e20bd117df1d9f6e
MD5 fcfd66802f233d92796af5fb0ca29072
BLAKE2b-256 c8196f6e2352ee1c4388cbf660cb783a80ae56dddf15bd63e7e397eb6c86ceee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0b4981eed00b457c02c1072a153870cc1e7471f5aece031047b31e8bbf9a26b6
MD5 280427f6fb36d240b3e9c2e104b2bf2c
BLAKE2b-256 a5a979817724462741c2d792209b1a7ee8b4807787b07b40bf72b6c6346b2c63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8a159c615c21f77366a889c3a4384f7709d7bef976fc5bc4542878ed3d395c0
MD5 26350bafe0fe4e6005053cc3a6787db8
BLAKE2b-256 ddb116b6847f071e8af71111e7788971ba1fb5e838685b7c2c5b2cf682d153b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b9188771e5ba2beabb0776183c677abbc5b4b9afa8f12818ae5fd56c147f4480
MD5 c68fa896a3871fd728c024ed37be18b5
BLAKE2b-256 c8ff50d9547b8423dded9a39cc6dbb93a81a60f3623de097ed5755772a05ea3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 ed07a9e1a26df355d2879bd02fb192e34e176e728f9f1d48d779f40b4eb43217
MD5 283af12a5565f68112e5d117a31666a9
BLAKE2b-256 3e22f284a237f8894f086b1532df19da1e7c9c4bfcc6b389a06088d0741b4559

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3f0b35f30757ac7f3ee0907b6777f2d4c854f13dfb7969d853de6a2da4833a36
MD5 82c7798974c9964e9fdf1dab757d39c1
BLAKE2b-256 798909915540927ef4d4478abd63f3a3623b7b2e6ed0c02c9dba18adbb069394

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e34114782735b854980d6fb8786159fc8164f936d7a503132e4f74c206a2f001
MD5 56f154928731713cfd7c8b5eae8e2e06
BLAKE2b-256 b23de43d46af6db30970984d6894349e2a9908c5480850e97f750cebda7e3bb4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e50df3c50e3f6996d66b8891084599faed6b299899a8e254fc1c8918e833c5be
MD5 07b77875db4b104fecea8d3b64a5a080
BLAKE2b-256 1ec8ad07d32762f413d9655a8d73f6627eda1fef04643074640344c3b4a7c72e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 a59b20a774a12c39671453428da8fa640974ddb1a38f2779e2846077f04644fb
MD5 29282a57ebcc5ff5d0c807954bae9955
BLAKE2b-256 e88e0cb3a5e43639954834b1a9f0d957f9a6264cff54969ee5ae2d657688393a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 28681f73f7aca16ab76a5e150f5975bc1fd84e8b8e4536cd5364bff3940e3d6f
MD5 c31a79205f843364022ee9ca0d95e942
BLAKE2b-256 c14868a43f57a1d126c759489df9441b08c179785ab8ae0c8694f05319ffaa6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0cebc447443b8ad6addf6d5206000faad38094aacd9b037ee83b011fc81889a9
MD5 fb2be556cb5924323715a9f1ef9cf0c6
BLAKE2b-256 3d0ac5a3693bcfb2999a2cad3688ec691f26b01d26ee000cc44045bc2dba1823

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.2-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 82e7b4ddac201f222fa14464d753b3edbbf6d698aa277007077c643b7d3c01b9
MD5 2508aaff126f35b7c094cb1fac3f62da
BLAKE2b-256 d0041ad2f6d9bdfc696e5cb84ed1d3d7f89650724d571d623f1aca62bed72da5

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