Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

httpmq

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpmq

HTTP MQ Python client module

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

HTTP MQ - Python Client

Python client for httpmq

MIT CICD workflow PyPI version

Table of Content


1. Introduction

This is a async Python client SDK for httpmq built around aiohttp, and uses the auto-generated data models of httpmq's OpenAPI specification. The auto-generated data models are placed under httpmq/models. The module provides client objects for interacting with the management and data plane API of httpmq.

import asyncio
import logging
import httpmq


async def async_main(log: logging.Logger):
    try:
        # Create management plane client
        mgmt_client = httpmq.ManagementClient(
            api_client=httpmq.APIClient(base_url="http://127.0.0.1:4100")
        )
        # Create data plane client
        data_client = httpmq.DataClient(
            api_client=httpmq.APIClient(base_url="http://127.0.0.1:4101")
        )

        # Check whether management plane is ready
        await mgmt_client.ready(context=httpmq.RequestContext())
        log.info("Management API ready")

        # Check whether data plane is ready
        await data_client.ready(context=httpmq.RequestContext())
        log.info("Data plane API ready")
    finally:
        # Always disconnect
        await mgmt_client.disconnect()
        await data_client.disconnect()

2. Installation

$ pip3 install httpmq

3. Examples

4. Local Development

NOTE: Though the described procedures supports local development, the same docker-compose.yaml can be used to create a httpmq test environment independent of this project.

This project uses Poetry as the dependency management framework.

$ poetry check
All set!

A helper Makefile is also included to automate the common development tasks. The available make targets are:

$ make help
lint                           Run python lint
build                          Build module
test                           Run unit-tests
one-test                       Run specific unit-tests
install                        Install module
uninstall                      Uninstall module
reinstall                      Reinstall module
cli                            Run venv python CLI
compose                        Bring up development environment via docker-compose
clean                          Clean up the python build artifacts
help                           Display this help screen

First, prepare the development environment:

make

This will call Poetry to setup the virtual environment, install dependencies, and build the module.

Now, start the development environment:

$ make compose
docker-compose -f docker-compose.yaml down --volume
Removing network httpmq-python_httpmq-py-test
WARNING: Network httpmq-python_httpmq-py-test not found.
docker-compose -f docker-compose.yaml up -d
Creating network "httpmq-python_httpmq-py-test" with driver "bridge"
Creating httpmq-python_httpmq-data_1 ... done
Creating httpmq-python_httpmq-mgmt_1 ... done
Creating httpmq-python_dev-nats_1    ... done

Verify the code passes unit-tests:

$ make test
poetry run pytest --verbose --junitxml=test-reports/test.xml test/
=============================================== test session starts ===============================================
platform linux -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0 -- /home/harry/Git/HTTP_Message_Broker/httpmq-python/.venv/bin/python
cachedir: .pytest_cache
rootdir: /home/harry/Git/HTTP_Message_Broker/httpmq-python
collected 11 items

test/test_client.py::TestAPIClient::test_delete PASSED                                                      [  9%]
test/test_client.py::TestAPIClient::test_get PASSED                                                         [ 18%]
test/test_client.py::TestAPIClient::test_post PASSED                                                        [ 27%]
test/test_client.py::TestAPIClient::test_put PASSED                                                         [ 36%]
test/test_client.py::TestAPIClient::test_sse_get PASSED                                                     [ 45%]
test/test_dataplane.py::TestDataplane::test_basic_sanity PASSED                                             [ 54%]
test/test_dataplane.py::TestDataplane::test_message_splitter PASSED                                         [ 63%]
test/test_dataplane.py::TestDataplane::test_push_subscribe PASSED                                           [ 72%]
test/test_management.py::TestManagement::test_basic_sanity PASSED                                           [ 81%]
test/test_management.py::TestManagement::test_consumer_management PASSED                                    [ 90%]
test/test_management.py::TestManagement::test_stream_management PASSED                                      [100%]

----------- generated xml file: /home/harry/Git/HTTP_Message_Broker/httpmq-python/test-reports/test.xml -----------
=============================================== 11 passed in 2.62s ================================================

A demo application, scripts/httpmq_test_cli.py, is also provided. It exercises all the functionalities of the httpmq APIs. These functionalities are separated into subcommands, and the associated usage message explains how to call each functionality.

IMPORTANT: Before starting, perform

$ make install
$ poetry shell

This will install the locally built SDK package into the local virtual environment, and start a new shell within that virtual environment.

$ ./scripts/httpmq_test_cli.py --help
Usage: httpmq_test_cli.py [OPTIONS] COMMAND [ARGS]...

  Demo application for trying out functionalities of httpmq

Options:
  --custom-ca-file, --ca TEXT  Custom CA file to use with HTTP client  [env
                               var: HTTP_CUSTOM_CA_FILE]
  --access-token, --at TEXT    Bearer access token used for authentication
                               [env var: HTTP_BEARER_ACCESS_TOKEN]
  --request-id, --rid TEXT     Request ID to use with this call  [default:
                               6403e98e-d29a-478b-99e4-49ff07fb210f]
  -v, --verbose                Verbose logging
  --help                       Show this message and exit.

Commands:
  data    Operate the httpmq dataplane API
  manage  Operate the httpmq management API
$ ./scripts/httpmq_test_cli.py manage --help
Usage: httpmq_test_cli.py manage [OPTIONS] COMMAND [ARGS]...

  Operate the httpmq management API

Options:
  -s, --management-server-url TEXT
                                  Management server URL  [env var:
                                  MANAGEMENT_SERVER_URL; default:
                                  http://127.0.0.1:4100]
  --help                          Show this message and exit.

Commands:
  consumer  Manages consumers through httpmq management API
  ready     Verify the management API is ready
  stream    Manages streams through httpmq management API
$ ./scripts/httpmq_test_cli.py manage ready --help
Usage: httpmq_test_cli.py manage ready [OPTIONS]

  Verify the management API is ready

Options:
  --help  Show this message and exit.
$ ./scripts/httpmq_test_cli.py manage stream --help
Usage: httpmq_test_cli.py manage stream [OPTIONS] COMMAND [ARGS]...

  Manages streams through httpmq management API

Options:
  --help  Show this message and exit.

Commands:
  change-retention  Changed a stream's message retention policy.
  change-subject    Changed the target subjects of a stream through management API
  create            Define a new stream through httpmq management API
  delete            Delete one stream through management API
  get               Read information regarding one stream through management API
  list-all          List all streams through httpmq management API
$ ./scripts/httpmq_test_cli.py manage consumer --help
Usage: httpmq_test_cli.py manage consumer [OPTIONS] COMMAND [ARGS]...

  Manages consumers through httpmq management API

Options:
  -s, --target-stream TEXT  Target stream to operate against  [env var:
                            TARGET_STREAM; required]
  --help                    Show this message and exit.

Commands:
  create    Define a new consumer through httpmq management API
  delete    Delete a consumer through httpmq management API
  get       Read information regarding one consumer through management API
  list-all  List all consumers of a stream through httpmq management API
$ ./scripts/httpmq_test_cli.py data --help
Usage: httpmq_test_cli.py data [OPTIONS] COMMAND [ARGS]...

  Operate the httpmq dataplane API

Options:
  -s, --dataplane-server-url TEXT
                                  Dataplane server URL  [env var:
                                  DATAPLANE_SERVER_URL; default:
                                  http://127.0.0.1:4101]
  --help                          Show this message and exit.

Commands:
  pub    Publish messages on a subject through httpmq dataplane API
  ready  Verify the dataplane API is ready
  sub    Subscribe for messages as a consumer on a stream through httpmq dataplane API
$ ./scripts/httpmq_test_cli.py data ready --help
Usage: httpmq_test_cli.py data ready [OPTIONS]

  Verify the dataplane API is ready

Options:
  --help  Show this message and exit.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc