Skip to main content

mrkutil

This is a Python package containing common functions for Python service-based architecture.

Base Handler

BaseHandler is an abstract class used for implementing function/class level factory pattern.

data = ["method"] = "my_defined_method"
handler = BaseHandler.process_data(data)

Where my_defined_method is the name of the child handler name static method.

Base Redis

Simple class with utility functions for working with redis. Key is the prefix for all redis objects, and timeout is how long redis keeps the object in cache. Example usage:

cache = RedisBase(key="key", timeout=300)
res = cache.get("this_key")

Communication

Communication package is a wrapper arround RabbitMQPubSub library that provides a simple interface for publishing and subscribing to messages.

call_service is a function that can be used to call a service with a message and await its response.

call_service(request_data=data, destination="some_exchange", source="self_exchange")

listen is a function that can be used to listen to a queue and call a function when a message is received. Commonly implemented in microservices in main.py as a long living process.

listen(exchange="some_exchange", exchange_type="direct", queue="some_queue")

trigger_service triggers a service with a message but does not wait for a response. Useful for fire and forget scenarios.

trigger_service(request_data=data, destination="some_exchange", source="self_exchange")

Logging Configuration

The get_logging_config function in mrkutil/logging/logging_config.py generates a logging configuration dictionary based on the provided parameters. It supports both JSON and default formatters.

config = get_logging_config(log_level="DEBUG", json_format=False, api=True)

Pagination

The paginate function in mongoengine.py and sqlalchemy.py is a utility function that paginates a list of items based on the provided page and page size. It is useful in microservices where there is no accessible web framework pagination method, and to avoid code duplication.

There is also a dependency.py which contains pagination_params function that are usually used in fastapi dependency injection.

paginate(items, page_number=1, page_size=10, direction="asc", sort_by="id")

Responses

ServiceResponse class is a utility class for creating a standard response object that can be used in all services. It is useful for standardizing the response format across all services.

ServiceResponse(code=400, message="Validation Error", errors=[{"field": "name", "message": "Name is required"}])

Authors

Deployment to PyPI

To deploy this package to PyPI, use the following commands:

flit build
flit publish

Contributing

Contributions are always welcome! If you have any suggestions or improvements, feel free to submit a pull request or open an issue.

Metadata

Release files for mrkutil 2.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mrkutil 2.1.1
File Size Uploaded
mrkutil-2.1.1.tar.gz 76.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mrkutil 2.1.1
File Interpreter ABI Platform
mrkutil-2.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 102.8 kB

Release files / mrkutil-2.1.1.tar.gz

Download URL mrkutil-2.1.1.tar.gz
Size 76.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8dfcedbc3f0a0f206ab8633901023a6642b40c29fca1c9e146e73a01e1977cc9
BLAKE2b-256 checksum
How to use checksums
18562d1f125975955e379d9fc35fec1d05ddbe5c4626ba1b88796e3684c152d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / mrkutil-2.1.1-py3-none-any.whl

Download URL mrkutil-2.1.1-py3-none-any.whl
Size 25.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83bdad9c1000ac7e84dcf939a943bed968553429a86518f7d9f994280a27ec53
BLAKE2b-256 checksum
How to use checksums
8e60164bf0a9eedb99a3429f03cb043c632ad16894e45fc73b67f01e9250f5a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release history Release notifications | RSS feed

This release

2.1.1 This release

2 release files

2.1.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.8.7

2 release files

1.8.6

2 release files

1.8.5

2 release files

1.8.4

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.8

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page