Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Python client for httpmq
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()
$ pip3 install httpmq
Hello World: basic example showing how to define the client.
Manage Streams: managing streams through the management
API.
Manage Consumers: managing consumers through the management
API.
Sending and Receiving Messages: sending and receiving messages.
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.
FAQs
HTTP MQ Python client module
We found that httpmq demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.