Skip to main content

Nanos

logo

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

Metadata

Release files for nanos 0.1.9

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

Source distribution (sdist)

Source distribution for nanos 0.1.9
File Size Uploaded Provenance Actions
nanos-0.1.9.tar.gz 12.8 kB Without provenance Details for nanos-0.1.9.tar.gz

Built distribution (wheel)

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

Total release size: 26.2 kB

Release files / nanos-0.1.9.tar.gz

Download URL nanos-0.1.9.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0e6d3f0c99321e3f452b03a103adf9b265934fac6fbfecdf28567db004415f8d
BLAKE2b-256 checksum
How to use checksums
1d0120e9e9737fdd1390c28149071fb0e88931ba57aae406194d0e56e48db4a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.19 Linux/6.11.0-1018-azure

Release files / nanos-0.1.9-py3-none-any.whl

Download URL nanos-0.1.9-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd56c38bd818e8bfcdab631d3f505ce31c622336f76839bcb9ecdee304ca0092
BLAKE2b-256 checksum
How to use checksums
38545270f3414f4c4057e2bffc0a0e43edd712cb0441ffb76cb1a53561810263
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.19 Linux/6.11.0-1018-azure

Security for nanos 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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