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).
from configparser import ConfigParser
import purse.logs
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).
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.
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:
pip install python-purse
Contributing
Contributions are welcome! If you’d like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch (git checkout -b feature/my-feature).
- Commit your changes (git commit -am 'Add new feature').
- Push your branch (git push origin feature/my-feature).
- Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contacts
Metadata
Release files for python-purse 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| python_purse-1.1.2.tar.gz | 39.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| python_purse-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 77.5 kB
Release files / python_purse-1.1.2.tar.gz
| Download URL | python_purse-1.1.2.tar.gz |
|---|---|
| Size | 39.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64d47232f05950323792827801933813b50c5123365ee9c873c9de9089ba5442
|
|
BLAKE2b-256 checksum How to use checksums |
229d8a19ddf1cdc59992158e4292ad0c88e9ebc497eff16ec5e503fdb06546ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.10
|
Release files / python_purse-1.1.2-py3-none-any.whl
| Download URL | python_purse-1.1.2-py3-none-any.whl |
|---|---|
| Size | 38.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2bf95eef8d9f22d7fa2dc95e9e56ad76f5db90c51840cd777724913dc73c468
|
|
BLAKE2b-256 checksum How to use checksums |
8e7ad00165a91c086bb47a1d8c4ebfb42006b957ab8f810d47ddf907b970111d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.10
|