Collection of small utility-functions
Project description
Nanos
Nanos is a collection of small but handy Python utilities: different functions, classes and mixins. The library has zero dependencies and relies only on built-in Python modules.
Complete documentation: https://nanos.readthedocs.io/en/latest/index.html
Features
- Data Processing - Utilities for working with data structures (chunking, ID mapping, empty value handling)
- Date & Time - Helper functions for common date operations and time measurements
- Formatting - Human-readable formatting for data types (file sizes, etc.)
- Logging - Simple logging setup and convenient LoggerMixin
- Zero Dependencies - Works with just the Python standard library
Installation
Library is available on PyPI and can be installed using pip:
pip install nanos
Quick Examples
Format file sizes
from nanos import fmt
print(fmt.size(1024)) # 1.00 KiB
print(fmt.size(1572864)) # 1.50 MiB
print(fmt.size(3.5 * 10**9)) # 3.26 GiB
Measure execution time
import time
from nanos import time as ntime
with ntime.Timer() as t:
time.sleep(1.5)
print(t.elapsed) # 1.5033...
print(t) # 0:00:01.50
Date helpers
from nanos import dt
import datetime
# Get tomorrow's date in UTC
tomorrow = dt.tomorrow()
# Get yesterday's start/end timestamps
day_start = dt.yesterday_start()
day_end = dt.yesterday_end()
Data processing
from nanos import data
# Split a list into chunks
chunks = data.chunker(range(10), 3) # [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
# Convert a list of objects to a dict indexed by ID
users = [{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}]
users_by_id = data.idfy(users) # {1: {"id": 1, "name": "Alice"}, 2: {"id": 2, "name": "Bob"}}
# Remove empty values from nested data
cleaned = data.remove_empty_members({"user": {"name": "Alice", "bio": ""}}) # {"user": {"name": "Alice"}}
Simple logging setup
from nanos import logging
# Get a pre-configured logger with console output
logger = logging.get_simple_logger(name="myapp")
logger.info("Application started") # 2023-05-01T12:34:56 myapp INFO Application started
# Use LoggerMixin in your classes
class MyService(logging.LoggerMixin):
def process(self):
self.logger.debug("Processing started") # mypackage.MyService DEBUG Processing started
Type Hinting
Nanos is fully typed and includes a py.typed marker file for better IDE support.
License
The library is released under the Apache License 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nanos-0.1.9.tar.gz.
File metadata
- Download URL: nanos-0.1.9.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.19 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e6d3f0c99321e3f452b03a103adf9b265934fac6fbfecdf28567db004415f8d
|
|
| MD5 |
c9b896922e7b0db603eb2a8f8dd1baa3
|
|
| BLAKE2b-256 |
1d0120e9e9737fdd1390c28149071fb0e88931ba57aae406194d0e56e48db4a9
|
File details
Details for the file nanos-0.1.9-py3-none-any.whl.
File metadata
- Download URL: nanos-0.1.9-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.10.19 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd56c38bd818e8bfcdab631d3f505ce31c622336f76839bcb9ecdee304ca0092
|
|
| MD5 |
8f309ca8adcaf02820abc2c114815c7d
|
|
| BLAKE2b-256 |
38545270f3414f4c4057e2bffc0a0e43edd712cb0441ffb76cb1a53561810263
|