Skip to main content

ry = rust + python kitchen sink utils (WIP)

Project description

ry

rust + python kitchen sink library

What and why?

This is a collection of pyo3-wrappers for rust crates I wish existed in python.

It all started with me wanting a fast fnv1a-64

Who?

Me (jesse(krubin)), and possibly you!?

FAQ

(aka: questions that I have been asking myself)

  • Q: Why?
    • A: I (jesse) needed several hashing functions for python and then kept adding things as I needed them
  • Q: Does this have anything to do with the (excellent) package manager rye?
    • A: short answer: no. long answer: no, it does not.
  • Q: Why is the repo split into ry and ryo3?
    • A: ry is the python package, ryo3 is a rust crate setup to let you "register" functions you may want if you were writing your own pyo3-python bindings library; maybe someday the ryo3::libs module will be split up into separate packages

Crate bindings

  • which
  • fnv
  • shlex
  • walkdir
  • xxhash
  • zstd
  • flate2
  • bzip2
  • brotli
  • TBD:
    • globset
    • regex
    • tokio (fs + process)
    • tracing (could be nicer than python's awful logging lib)
    • reqwest (http client)

API

"""ry api ~ type annotations"""

from os import PathLike
from typing import AnyStr, Iterator, final

__version__: str
__authors__: str
__build_profile__: str
__build_timestamp__: str

# ==============================================================================
# TYPE ALIASES
# ==============================================================================
JsonPrimitive = None | bool | int | float | str
JsonValue = (
    JsonPrimitive
    | dict[str, JsonPrimitive | JsonValue]
    | list[JsonPrimitive | JsonValue]
)

class FsPath:
    def __init__(self, path: str | None = None) -> None: ...
    def __str__(self) -> str: ...
    def __repr__(self) -> str: ...
    def __eq__(self, other: object) -> bool: ...
    def __ne__(self, other: object) -> bool: ...

FsPathLike = str | FsPath | PathLike[str]

def pwd() -> str: ...
def cd(path: FsPathLike) -> None: ...
def ls(path: FsPathLike | None = None) -> list[FsPath]: ...

# ==============================================================================
# SLEEP
# ==============================================================================
def sleep(seconds: float) -> float: ...
async def sleep_async(seconds: float) -> float: ...

# ==============================================================================
# FILESYSTEM
# ==============================================================================
def read_text(path: FsPathLike) -> str: ...
def read_bytes(path: FsPathLike) -> bytes: ...

# ==============================================================================
# WHICH
# ==============================================================================
def which(cmd: str, path: None | str = None) -> str | None: ...
def which_all(cmd: str, path: None | str = None) -> list[str]: ...

# ==============================================================================
# WALKDIR
# ==============================================================================
class Walkdir:
    files: bool
    dirs: bool
    def __next__(self) -> str: ...
    def __iter__(self) -> Iterator[str]: ...

def walkdir(
    path: FsPathLike | None = None,
    files: bool = True,
    dirs: bool = True,
    contents_first: bool = False,
    min_depth: int = 0,
    max_depth: int | None = None,
    follow_links: bool = False,
    same_file_system: bool = False,
) -> Walkdir: ...

# ==============================================================================
# SHLEX
# ==============================================================================
def shplit(s: str) -> list[str]: ...

# ==============================================================================
# JSON
# ==============================================================================
def parse_json(input: str | bytes) -> JsonValue: ...
def parse_json_str(input: str) -> JsonValue: ...
def parse_json_bytes(input: bytes) -> JsonValue: ...

# ==============================================================================
# FORMATTING
# ==============================================================================
def fmt_nbytes(nbytes: int) -> str: ...

# ==============================================================================
# FNV
# ==============================================================================
class FnvHasher:
    def __init__(self, input: bytes | None = None) -> None: ...
    def update(self, input: bytes) -> None: ...
    def digest(self) -> int: ...
    def hexdigest(self) -> str: ...
    def copy(self) -> FnvHasher: ...
    def __str__(self) -> str: ...
    def __repr__(self) -> str: ...

def fnv1a(input: bytes) -> FnvHasher: ...

# ==============================================================================
# DEV
# ==============================================================================
def anystr_noop(s: AnyStr) -> AnyStr: ...

# ==============================================================================
# BROTLI
# ==============================================================================
def brotli_encode(
    input: bytes, quality: int = 11, magic_number: bool = False
) -> bytes: ...
def brotli_decode(input: bytes) -> bytes: ...
def brotli(input: bytes, quality: int = 11, magic_number: bool = False) -> bytes:
    """Alias for brotli_encode"""

# ==============================================================================
# BZIP2
# ==============================================================================
def bzip2_encode(input: bytes, quality: int = 9) -> bytes: ...
def bzip2_decode(input: bytes) -> bytes: ...
def bzip2(input: bytes, quality: int = 9) -> bytes:
    """Alias for bzip2_encode"""

# ==============================================================================
# GZIP
# ==============================================================================
def gzip_encode(input: bytes, quality: int = 9) -> bytes: ...
def gzip_decode(input: bytes) -> bytes: ...
def gzip(input: bytes, quality: int = 9) -> bytes:
    """Alias for gzip_encode"""

# ==============================================================================
# ZSTD
# ==============================================================================
def zstd_encode(input: bytes, level: int = 3) -> bytes: ...
def zstd(input: bytes, level: int = 3) -> bytes:
    """Alias for zstd_encode"""

def zstd_decode(input: bytes) -> bytes: ...

# ==============================================================================
# XXHASH
# ==============================================================================
@final
class Xxh32:
    def __init__(self, input: bytes = ..., seed: int | None = ...) -> None: ...
    def update(self, input: bytes) -> None: ...
    def digest(self) -> bytes: ...
    def hexdigest(self) -> str: ...
    def intdigest(self) -> int: ...
    def copy(self) -> Xxh32: ...
    def reset(self, seed: int | None = ...) -> None: ...
    @property
    def name(self) -> str: ...
    @property
    def seed(self) -> int: ...

@final
class Xxh64:
    def __init__(self, input: bytes = ..., seed: int | None = ...) -> None: ...
    def update(self, input: bytes) -> None: ...
    def digest(self) -> bytes: ...
    def hexdigest(self) -> str: ...
    def intdigest(self) -> int: ...
    def copy(self) -> Xxh32: ...
    def reset(self, seed: int | None = ...) -> None: ...
    @property
    def name(self) -> str: ...
    @property
    def seed(self) -> int: ...

@final
class Xxh3:
    def __init__(
        self, input: bytes = ..., seed: int | None = ..., secret: bytes | None = ...
    ) -> None: ...
    def update(self, input: bytes) -> None: ...
    def digest(self) -> bytes: ...
    def hexdigest(self) -> str: ...
    def intdigest(self) -> int: ...
    @property
    def name(self) -> str: ...
    @property
    def seed(self) -> int: ...
    def digest128(self) -> bytes: ...
    def hexdigest128(self) -> str: ...
    def intdigest128(self) -> int: ...
    def copy(self) -> Xxh3: ...
    def reset(self) -> None: ...

def xxh32(input: bytes | None = None, seed: int | None = None) -> Xxh32: ...
def xxh64(input: bytes | None = None, seed: int | None = None) -> Xxh64: ...
def xxh3(
    input: bytes | None = None, seed: int | None = None, secret: bytes | None = None
) -> Xxh3: ...

# xxh32
def xxh32_digest(input: bytes, seed: int | None = None) -> bytes: ...
def xxh32_hexdigest(input: bytes, seed: int | None = None) -> str: ...
def xxh32_intdigest(input: bytes, seed: int | None = None) -> int: ...

# xxh64
def xxh64_digest(input: bytes, seed: int | None = None) -> bytes: ...
def xxh64_hexdigest(input: bytes, seed: int | None = None) -> str: ...
def xxh64_intdigest(input: bytes, seed: int | None = None) -> int: ...

# xxh128
def xxh128_digest(input: bytes, seed: int | None = None) -> bytes: ...
def xxh128_hexdigest(input: bytes, seed: int | None = None) -> str: ...
def xxh128_intdigest(input: bytes, seed: int | None = None) -> int: ...

# xxh3
def xxh3_64_digest(input: bytes, seed: int | None = None) -> bytes: ...
def xxh3_64_intdigest(input: bytes, seed: int | None = None) -> int: ...
def xxh3_64_hexdigest(input: bytes, seed: int | None = None) -> str: ...

DEV

just is used to run tasks.

SEE ALSO

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ry-0.0.6.tar.gz (67.0 kB view hashes)

Uploaded Source

Built Distributions

ry-0.0.6-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ry-0.0.6-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

ry-0.0.6-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

ry-0.0.6-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

ry-0.0.6-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

ry-0.0.6-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

ry-0.0.6-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

ry-0.0.6-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

ry-0.0.6-cp312-none-win_amd64.whl (2.2 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

ry-0.0.6-cp312-none-win32.whl (2.1 MB view hashes)

Uploaded CPython 3.12 Windows x86

ry-0.0.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ry-0.0.6-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

ry-0.0.6-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

ry-0.0.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

ry-0.0.6-cp312-cp312-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ry-0.0.6-cp312-cp312-macosx_10_12_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

ry-0.0.6-cp311-none-win_amd64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

ry-0.0.6-cp311-none-win32.whl (2.1 MB view hashes)

Uploaded CPython 3.11 Windows x86

ry-0.0.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ry-0.0.6-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

ry-0.0.6-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

ry-0.0.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

ry-0.0.6-cp311-cp311-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ry-0.0.6-cp311-cp311-macosx_10_12_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

ry-0.0.6-cp310-none-win_amd64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

ry-0.0.6-cp310-none-win32.whl (2.1 MB view hashes)

Uploaded CPython 3.10 Windows x86

ry-0.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ry-0.0.6-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

ry-0.0.6-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

ry-0.0.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

ry-0.0.6-cp310-cp310-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ry-0.0.6-cp310-cp310-macosx_10_12_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

ry-0.0.6-cp39-none-win_amd64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

ry-0.0.6-cp39-none-win32.whl (2.1 MB view hashes)

Uploaded CPython 3.9 Windows x86

ry-0.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ry-0.0.6-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (2.5 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

ry-0.0.6-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

ry-0.0.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

ry-0.0.6-cp39-cp39-macosx_11_0_arm64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ry-0.0.6-cp39-cp39-macosx_10_12_x86_64.whl (2.3 MB view hashes)

Uploaded CPython 3.9 macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page