Skip to main content

(XLOFT) X-Library of tools

Project description

Logo

XLOFT

(XLOFT) X-Library of tools.

Build Status Docs PyPI pyversions PyPI status PyPI version fury.io
Types: Pyrefly Code style: Ruff Format PyPI Downloads GitHub license

The collection is represented by three modules of `NamedTuple`, `Converters`, `ItIs`.
In the future, new tools can be added.


Documentation

Online browsable documentation is available at https://kebasyaty.github.io/xloft/.

Requirements

View the list of requirements.

Installation

uv add xloft

Usage

  • NamedTuple
"""This class imitates the behavior of the `named tuple`."""

from xloft import NamedTuple


nt = NamedTuple(x=10, y="Hello", _id="507c7f79bcf86cd7994f6c0e")
# or
d = {"x": 10, "y": "Hello", "_id": "507c7f79bcf86cd7994f6c0e"}
nt = NamedTuple(**d)

nt.x  # => 10
nt.y  # => Hello
nt._id  # => 507c7f79bcf86cd7994f6c0e
nt.z  # => raise: KeyError

len(nt)  # => 3
nt.keys()  # => ["x", "y", "_id"]
nt.values()  # => [10, "Hello", "507c7f79bcf86cd7994f6c0e"]

nt.has_key("x")  # => True
nt.has_key("y")  # => True
nt.hsa_key("_id")  # => True
nt.has_key("z")  # => False

nt.has_value(10)  # => True
nt.has_value("Hello")  # => True
nt.has_value("507c7f79bcf86cd7994f6c0e")  # => True
nt.has_value([1, 2, 3])  # => False

nt.get("x")  # => 10
nt.get("y")  # => Hello
nt.get("_id")  # => 507c7f79bcf86cd7994f6c0e
nt.get("z")  # => None

d = nt.to_dict()
d["x"]  # => 10
d.get("y")  # => Hello
d.get("z") # => None

for key, val in nt.items():
    print(f"Key: {key}, Value: {val}")

nt.update("x", 20)
nt.update("y", "Hi")
nt.update("_id", "new_id")
nt.x  # => 20
nt.y  # => Hi
nt._id  # => new_id
nt.update("z", [1, 2, 3])  # => raise: KeyError

nt["x"]  # => raise: KeyError
nt["y"]  # => raise: KeyError
nt["_id"]  # => raise: KeyError
nt["z"]  # => raise: KeyError
nt["x"] = 20  # => TypeError
nt["y"] = "Hi"  # => TypeError
nt["_id"] = "new_id"  # => TypeError
nt["z"] = [1, 2, 3]  # => TypeError

nt.x = 20  # => raise: AttributeDoesNotSetValueError
nt.y = "Hi"  # => raise: AttributeDoesNotSetValueError
nt._id = "new_id"  # => raise: AttributeDoesNotSetValueError
nt.z = [1, 2, 3]  # => raise: AttributeDoesNotSetValueError

del nt.x  # => raise: AttributeCannotBeDeleteError
del nt.y # => raise: AttributeCannotBeDeleteError
del nt._id # => raise: AttributeCannotBeDeleteError
  • Converters
"""Convert the number of bytes into a human-readable format."""

from xloft import to_human_size, int_to_roman, roman_to_int
# from xloft.converters import to_human_size, int_to_roman, roman_to_int


to_human_size(200)  # => 200 bytes
to_human_size(1048576)  # => 1 MB
to_human_size(1048575)  # => 1023.999 KB
#
int_to_roman(1994)  # => MCMXCIV
roman_to_int("MCMXCIV")  # => 1994
  • ItIs
"""Check if a string is a number."""

from xloft import is_number, is_palindrome
# from xloft.itis import is_number, is_palindrome


is_number("")  # => False
is_number(" ")  # => False
is_number("1230.")  # => False
is_number("0x5")  # => False
is_number("0o5")  # => False
is_number("-5.0")  # => True
is_number("+5.0")  # => True
is_number("5.0")  # => True
is_number(".5")  # => True
is_number("5.")  # => True
is_number("3.4E+38")  # => True
is_number("3.4E-38")  # => True
is_number("1.7E+308")  # => True
is_number("1.7E-308")  # => True
is_number("-1.7976931348623157e+308")  # => True
is_number("1.7976931348623157e+308")  # => True
is_number("72028601076372765770200707816364342373431783018070841859646251155447849538676")  # => True
is_number("-72028601076372765770200707816364342373431783018070841859646251155447849538676")  # => True
#
is_palindrome("racecar")  # True
is_palindrome("Go hang a salami, I'm a lasagna hog") # True
is_palindrome("22022022")  # True
is_palindrome("Gene")  # False
is_palindrome("123")  # False
is_palindrome(123)  # TypeError
is_palindrome("")  # ValueError

Changelog

View the change history.

License

This project is licensed under the MIT.

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

xloft-0.9.8-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file xloft-0.9.8-py3-none-any.whl.

File metadata

  • Download URL: xloft-0.9.8-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"42","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for xloft-0.9.8-py3-none-any.whl
Algorithm Hash digest
SHA256 55bf2b31f41e118979c1ce4b332518397f679bdd415bf4d062e7901b8c5875de
MD5 aac2eff7c3c6dec45943eaf700dc922b
BLAKE2b-256 d51e7d77c0442a72bb55786a22c50cb62cff24046d75624a4cee92ab206b940f

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