python-purse


Namepython-purse JSON
Version 1.0.29 PyPI version JSON
download
home_pageNone
SummarySnippets and utils for python projects
upload_time2025-02-09 16:50:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseCopyright 2025 Andrei Samofalov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords aiogram aiohttp logging python signals snippets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python‑purse

**python‑purse** is a library that collects a variety of snippets and utilities for both
asynchronous and synchronous Python projects. Whether you're building bots, web applications,
or other tools, this library provides ready-to-use code modules to speed up development.

## Framework Extensions

- **aiogram**: Bots and dp bootstrap, router-makers, useful decorators and utilities for Telegram bots.
- **aiohttp**: Simplified app creation and server utilities.
- **django**: ASGI/WSGI handlers, repository patterns, and more for Django projects.

## Logging

Custom logging configurations and integrations (including Telegram-based logging).

```python
from configparser import ConfigParser

import purse.logging

config = ConfigParser()
config.read('config.ini')
bot_config = config['bot']

tg_logger = purse.logging.setup(
    telegram_setup=purse.logging.TelegramSetup(
        bot=purse.logging.SimpleLoggingBot(token=bot_config.get('token')),
        log_chat_id=bot_config.get('log_chat_id'),
        send_delay=bot_config.getint('send_delay'),
        logger_level=bot_config.getint('logger_level'),
        service_name=bot_config.get('service_name'),
    ),
)

tg_logger.debug("dev message", to_dev=True)  # prints to stderr and sends message to telegram

try:
    raise Exception("some exception")
except Exception as exc:
    tg_logger.exception(exc)  # prints traceback to stderr and sends message to telegram

    
from logging import getLogger

your_app_logger = getLogger("app")
your_app_logger.error('error in runtime')  # prints to stderr and sends message to telegram

```
You don't have to use `purse.logging.setup` function return object (`tg_logger` in example above) 
directly for error/exception telegram logging unless you want to send messages 
by `TelegramLogger.to_tg(...)` and `TelegramLogger.to_dev(...)` methods.


## Interfaces and Repositories

Protocol definitions and in-memory repository implementations for fast prototyping and testing.

## JSON encoders and decoders

Utility functions and classes to simplify JSON handling (mostly decoding and encoding Decimals,
UUIDs, dates, and other specific types).

```python
from purse import json as purse_json
from decimal import Decimal

purse_json.dumps({"val": Decimal("100")})  # '{"val": "100"}'
purse_json.loads('{"val": "100"}')  # {'val': Decimal('100')}

```

## Asyncio signals handling

Easy loop signal setup for SIGINT and SIGTERM.
Use predefined `purse.signals.prepare_shutdown` (internal flag of this event would be set to True
when one of signals received) and `purse.signals.shutdown_complete` events in your code for more
compatability.

```python 
import purse
import asyncio 

async def main():
  kill_event = purse.signals.setup()
  ... # some startup logic
  
  await kill_event.wait()
  ... # some shutdown logic
  await purse.signals.shutdown_complete.wait()
  

if __name__ == '__main__':
    asyncio.run(main())
```

You can pass your custom function to `purse.signals.setup` for handling signals. This function
must have exact two arguments: `signal.Signals` and `asyncio.Event` (internal flag of this event
you must set to True due the function execution).

## Installation

You can install **python-purse** via pip (or with your another favorite manager) from PyPi:

```bash
pip install python-purse
```

## Contributing

Contributions are welcome! If you’d like to contribute, please follow these steps:

1. Fork the repository.
2. Create a new branch (git checkout -b feature/my-feature).
3. Commit your changes (git commit -am 'Add new feature').
4. Push your branch (git push origin feature/my-feature).
5. Open a pull request.

## License

This project is licensed under the MIT License. See the LICENSE file for details.

## Contacts

[email](mailto:andrei.e.samofalov@gmail.com)

[telegram](https://t.me/samofalov_andrey)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-purse",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "aiogram, aiohttp, logging, python, signals, snippets",
    "author": null,
    "author_email": "Andrei Samofalov <andrei.e.samofalov@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/5d/d5/38a994e771a2e1a622e720bf32291676fd080aac0db5c11e81f3bbb8998c/python_purse-1.0.29.tar.gz",
    "platform": null,
    "description": "# python\u2011purse\n\n**python\u2011purse** is a library that collects a variety of snippets and utilities for both\nasynchronous and synchronous Python projects. Whether you're building bots, web applications,\nor other tools, this library provides ready-to-use code modules to speed up development.\n\n## Framework Extensions\n\n- **aiogram**: Bots and dp bootstrap, router-makers, useful decorators and utilities for Telegram bots.\n- **aiohttp**: Simplified app creation and server utilities.\n- **django**: ASGI/WSGI handlers, repository patterns, and more for Django projects.\n\n## Logging\n\nCustom logging configurations and integrations (including Telegram-based logging).\n\n```python\nfrom configparser import ConfigParser\n\nimport purse.logging\n\nconfig = ConfigParser()\nconfig.read('config.ini')\nbot_config = config['bot']\n\ntg_logger = purse.logging.setup(\n    telegram_setup=purse.logging.TelegramSetup(\n        bot=purse.logging.SimpleLoggingBot(token=bot_config.get('token')),\n        log_chat_id=bot_config.get('log_chat_id'),\n        send_delay=bot_config.getint('send_delay'),\n        logger_level=bot_config.getint('logger_level'),\n        service_name=bot_config.get('service_name'),\n    ),\n)\n\ntg_logger.debug(\"dev message\", to_dev=True)  # prints to stderr and sends message to telegram\n\ntry:\n    raise Exception(\"some exception\")\nexcept Exception as exc:\n    tg_logger.exception(exc)  # prints traceback to stderr and sends message to telegram\n\n    \nfrom logging import getLogger\n\nyour_app_logger = getLogger(\"app\")\nyour_app_logger.error('error in runtime')  # prints to stderr and sends message to telegram\n\n```\nYou don't have to use `purse.logging.setup` function return object (`tg_logger` in example above) \ndirectly for error/exception telegram logging unless you want to send messages \nby `TelegramLogger.to_tg(...)` and `TelegramLogger.to_dev(...)` methods.\n\n\n## Interfaces and Repositories\n\nProtocol definitions and in-memory repository implementations for fast prototyping and testing.\n\n## JSON encoders and decoders\n\nUtility functions and classes to simplify JSON handling (mostly decoding and encoding Decimals,\nUUIDs, dates, and other specific types).\n\n```python\nfrom purse import json as purse_json\nfrom decimal import Decimal\n\npurse_json.dumps({\"val\": Decimal(\"100\")})  # '{\"val\": \"100\"}'\npurse_json.loads('{\"val\": \"100\"}')  # {'val': Decimal('100')}\n\n```\n\n## Asyncio signals handling\n\nEasy loop signal setup for SIGINT and SIGTERM.\nUse predefined `purse.signals.prepare_shutdown` (internal flag of this event would be set to True\nwhen one of signals received) and `purse.signals.shutdown_complete` events in your code for more\ncompatability.\n\n```python \nimport purse\nimport asyncio \n\nasync def main():\n  kill_event = purse.signals.setup()\n  ... # some startup logic\n  \n  await kill_event.wait()\n  ... # some shutdown logic\n  await purse.signals.shutdown_complete.wait()\n  \n\nif __name__ == '__main__':\n    asyncio.run(main())\n```\n\nYou can pass your custom function to `purse.signals.setup` for handling signals. This function\nmust have exact two arguments: `signal.Signals` and `asyncio.Event` (internal flag of this event\nyou must set to True due the function execution).\n\n## Installation\n\nYou can install **python-purse** via pip (or with your another favorite manager) from PyPi:\n\n```bash\npip install python-purse\n```\n\n## Contributing\n\nContributions are welcome! If you\u2019d like to contribute, please follow these steps:\n\n1. Fork the repository.\n2. Create a new branch (git checkout -b feature/my-feature).\n3. Commit your changes (git commit -am 'Add new feature').\n4. Push your branch (git push origin feature/my-feature).\n5. Open a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Contacts\n\n[email](mailto:andrei.e.samofalov@gmail.com)\n\n[telegram](https://t.me/samofalov_andrey)\n\n",
    "bugtrack_url": null,
    "license": "Copyright 2025 Andrei Samofalov  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Snippets and utils for python projects",
    "version": "1.0.29",
    "project_urls": {
        "Issues": "https://github.com/andrei-samofalov/purse/issues",
        "Repository": "https://github.com/andrei-samofalov/purse"
    },
    "split_keywords": [
        "aiogram",
        " aiohttp",
        " logging",
        " python",
        " signals",
        " snippets"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e2495f3c0a9e98a160494a9c568bf3c5549cc721e4afedda34b5cc23a6994253",
                "md5": "ae14b5806c9af651f25a7dce9c2261e0",
                "sha256": "f9c6b31c4526e925e0bbfe89e12a042cc0d6ffe61d4744fcd2a645710e920489"
            },
            "downloads": -1,
            "filename": "python_purse-1.0.29-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae14b5806c9af651f25a7dce9c2261e0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 36353,
            "upload_time": "2025-02-09T16:50:48",
            "upload_time_iso_8601": "2025-02-09T16:50:48.428209Z",
            "url": "https://files.pythonhosted.org/packages/e2/49/5f3c0a9e98a160494a9c568bf3c5549cc721e4afedda34b5cc23a6994253/python_purse-1.0.29-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5dd538a994e771a2e1a622e720bf32291676fd080aac0db5c11e81f3bbb8998c",
                "md5": "6dcf8026fed2d9970fc9f23b02315f56",
                "sha256": "21329d15ab836fb089cd664a52f753f8365f6ce6053b00e83b7b5e8086b7241d"
            },
            "downloads": -1,
            "filename": "python_purse-1.0.29.tar.gz",
            "has_sig": false,
            "md5_digest": "6dcf8026fed2d9970fc9f23b02315f56",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 36500,
            "upload_time": "2025-02-09T16:50:49",
            "upload_time_iso_8601": "2025-02-09T16:50:49.780254Z",
            "url": "https://files.pythonhosted.org/packages/5d/d5/38a994e771a2e1a622e720bf32291676fd080aac0db5c11e81f3bbb8998c/python_purse-1.0.29.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-09 16:50:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "andrei-samofalov",
    "github_project": "purse",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "python-purse"
}
        
Elapsed time: 0.50620s