Skip to main content

Python package containing common functions for python service based architecture.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mrkutil-1.8.7.1.tar.gz (52.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mrkutil-1.8.7.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file mrkutil-1.8.7.1.tar.gz.

File metadata

  • Download URL: mrkutil-1.8.7.1.tar.gz
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for mrkutil-1.8.7.1.tar.gz
Algorithm Hash digest
SHA256 ad7f7f3b1b58031f80f7cf7d9ab39c61763ed805e3f0422d8baaf678227c8c17
MD5 673a836f4e4a2cad0368e53b5e842829
BLAKE2b-256 1db86d11cb78a3d92cbab9a9d6d306e8c199deb8042b23053ff552ec978c7e09

See more details on using hashes here.

File details

Details for the file mrkutil-1.8.7.1-py3-none-any.whl.

File metadata

  • Download URL: mrkutil-1.8.7.1-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for mrkutil-1.8.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf816b8eb387d6cbb86dbb1ce88e5590b3a49e1ce411495de9579eb568d9b4b0
MD5 967de6399925c92fb4db952fad40e29e
BLAKE2b-256 ccd09fb487832cde8f85478a8220a7240937f773814178962e12d1fd2141216b

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