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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.8Windows x86-64

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 fe92ed54ea894fe58050f6ea6c579b35024a9d93d79827db9b0fdb047b86ded3
MD5 4a8f70bba52948fafe4a22151a02e5f4
BLAKE2b-256 8353b40967438e5df8830167250a2d6340335e5c8e6e61b94efa1f5922b9f493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 81aa1e5f88bab5dc640b877fb8c2157ea03d75359c316bb7182b669cae63bf87
MD5 86542ec54d2aef38196f318611b52d0f
BLAKE2b-256 bb8e545abab18395280f4358f31c3982cbaa70ab24f63b7871a4da9f786917b7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f978054d66d893ec59ff2e91733891a34f79d125ce3080c44824da26bbc1671
MD5 e66367377e3b7d3200403e7e623e99c6
BLAKE2b-256 4dff37c83c41d87b82063640b2fbfc18170b16345effbf2fb9a5e97393267f3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b38fc121e9a849e8fd8890243fc55f683ffb896ab3b90858153379328c7e1491
MD5 3c766b9a69cfd71b3bf9fbc8fa769910
BLAKE2b-256 85290d5ebee78ac48817d73e527fee255a1f6beb994243c15495d6e57b28f87e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 e91c04f32c4808b789b2654ffab3923b41adc9bf88b0ee0110bf0e78f4624987
MD5 f6616c5e929a8ef10fc4ff59205e0e98
BLAKE2b-256 f4cfbac2792b3090a92d7bcda4f310f371514fa5a37d42ba1ac63e9e17ca1bbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1a328676312a3000986b8f9480e808a7906d6e1a8d94be125651c46a5d9863fd
MD5 6791b6e090906bc6030ada111411c518
BLAKE2b-256 ff4c97308b887e19d01ecf7cb43e1015eeba1f4fe0dda2f20d6a018a21bba939

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 65f72a7ef83fd87772c48f85feb51322e5b9278fcb8a0ad5a920f55f423d69f5
MD5 2a024afee831188866f31c95e4a723ac
BLAKE2b-256 87afd9aae651675627bb3898c65a51a7f3089174e74fc489deb33ae9e11c7dc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6da82d0ee59bc8dcb382509e38d64a80cc288e0bbc25bf93b059763406ab5bd8
MD5 932ed4d90c5da5da8baab27fc4c0d159
BLAKE2b-256 c0ea18fb802f474a5109995f7b3d76d0fd3e0df161f5ff62a66837f909bc5da5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 817aedc4835c5052757c96d8a07885a7c8718903d9caf2b4556a1366efc85204
MD5 8b128ec8c9061de57795087310924b66
BLAKE2b-256 98c37cf2e8de3cb84835ebc5ed45d805fb73b2c4daf10ee65621e845e0b3e3f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 93a949655487fcda93b84f92483b2d83fad5d4ed6842ff092d084bb13442c4f8
MD5 ae308592288eb720c181b3dc928f6587
BLAKE2b-256 4c9994c98ae02957718e95ca9d0be81a860879f81ed20e8868ccfb6afd2aae2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 52f9705d4146fac3cdc4a13fca3f18e5ed3529a3c71492f097bffdbd6bc5530c
MD5 f7e5a80751443f50f5b25c5d11f2da3d
BLAKE2b-256 9d676944e129809b31ff26deff94d6029715fa0bf05cfcb01ec72632fdee6abe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 538ba7bdf564bbca2ab555d2a73b5c3d389e1b43a9695e713e65f34768be37b7
MD5 09d834bc1eec1aa4470af8e447c33346
BLAKE2b-256 bf03928d5a275f7de9b69272a939e4a3cc55175fab60c054f3a924b6fae55e33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 27bc9e5ea75c0bc86616b9be0911335a0e984815196ce23c88a0e0c854843afa
MD5 788f41a8ee92da462cd228b4b0a9661d
BLAKE2b-256 ef309aa5d3b90cb45066ce799f39cbb65205234496fe8711da2d8912177c597a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cdd6d1d1d4dd0ce057f5592b8a8c7e6a9d7f4e9bd438c141acba5fc2ed4d258e
MD5 bdd2dfe39352e62c032f1b57b4466286
BLAKE2b-256 f146faaa14c385fe54e4e8ac5c8847f2c19b2986f9bd662862eab9758e50e557

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a09cc0d03bc76d25281c6ae2e5904a6cd75fcb18bb1ae4c62755dcd235ba9869
MD5 f19465d2069c0ddde3601af1c2856c03
BLAKE2b-256 f03cda236fb05b3396fb59a13c620a1f1683818c3cf5e0438108dbef6f532a84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 51c9f02516b5acc054cd606f67882e641b65d189c7c34b13f32be5a6c2a109e3
MD5 6e946c05ad6c10704d12f440e875dca7
BLAKE2b-256 adb324bf972f1a74f14c87a3ee41893ddb04688563cdb86b02b3d4d36944ad5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 a54e981b78dc737e30d3e3128e573b1641eb4272d86d527aa63e19b7e7371499
MD5 03ba215250180bbf2f54e3c59cf39c81
BLAKE2b-256 20426425ac245de1d77abc402c68a1db38c61213fc9f6d67820cbd374bd6e974

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f38e36e42e4703adae6ab744ec8f88410341eff4f54f949330c6dc6559d06452
MD5 b527fcd27afdbf94d0f05128015f9eb4
BLAKE2b-256 592390b94b5daa372671522e731272aaedc881989e043b1c657b8f38e6f3b179

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9a15dc18becc37b7eb9c02cbc9dce2c0c795612c20a4e96b56d86248649a16d
MD5 7b1ce9c5bd66e759eb8e0b8fa77cfa52
BLAKE2b-256 443165ee207909444def2f8dcc320ca3e52cb03422583216ffabcfdab103d4f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for atomic_bomb_engine_py-0.3.3-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fdcc8b61f2a484f0010dee456106c12e0416539e6296e01c4f4918758ac974ee
MD5 0cc8bc5adab980a800dec8e284e91915
BLAKE2b-256 0435779169a1ca4e4f595a7128ab434e5cd377e7e26e8a45e5c2deef608de9a8

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