Skip to main content

An extensive utility library for python, focusing especially on iterables and a Regex 'Store'.

Project description

logo

myBasis: Ergonomic Python Utilities

Status: Pre-launch — under active development. APIs may change before 1.0.

Pipeline Status Test Coverage License

PyPI Version Python Version PyPI Wheel

pre-commit pyrefly ruff

The myBasis Python package contains a variety of utilities generally centered around the topics of text processing, functional programming, and runtime type coercion. This broad scope is somewhat unusual, as any given application will likely only need a small subset of the contents; for this reason, it is intended for use in applications where dependency purity isn't very important, such as personal projects, local development scripts, offline data-processing projects, and prototypes. As a rough sense of scale: a bare pip install my-basis pulls a couple dozen distributions (on the order of ~80 MB unpacked); turning on the optional extras (metrics, google, …) can push a full environment past ~290 MB.


See it in action

Two everyday chores, rewritten in front of you. Each clip is real my code: the fragile, hand-rolled version on the left collapses into the one-liner on the right.

One cast. Every field.

Coercing a raw config dict into a fully-typed Settings model with ty.cast

ty.cast reads the target type and coerces every field to match — int, tuple, bool, nested models and all. A whole page of int(...) / .split(",") / .lower() == "true" hand-parsing becomes a single, honest line.

A document, not a string.

Parsing markdown into a fence-aware node tree with Markdown.parse

Markdown.parse turns a document into a real, fence-aware tree you can .walk() to any depth. So pulling the sections out of a file stops being a startswith("## ") slicing exercise that silently breaks the moment a ## appears inside a code fence.


Install

my-basis is published to PyPI, so pip install my-basis (or uv add my-basis) works today — but it's pre-1.0 and still moving, so pin a version if you take it that way. Within this ecosystem, though, every sibling project consumes it the same way: as an editable local path wired through uv, so a change here is felt everywhere immediately, with no release round-trip.

# pyproject.toml
dependencies = [
  "my-basis",
  # ...
]

[tool.uv.sources]
my-basis = { path = "../libs/basis", editable = true }

Adjust the relative path to wherever this repo lives on disk from the consuming project, then run uv sync.

Quickstart

The core loop: cast untyped data into a target type, check whether a value already fits one, and introspect a type itself as a MyType node.

from my import ty, MyType

# Cast: coerce arbitrary data into a target type, best-effort.
ty.cast('42', int)                              # -> 42
ty.cast(['1', '2', '3'], list[int])             # -> [1, 2, 3]   (every element coerced)
ty.cast({'a': '1', 'b': '2'}, dict[str, int])   # -> {'a': 1, 'b': 2}

# Check: does this value already conform to a type, without coercing it?
ty.check(42, int)      # -> True
ty.check('42', int)    # -> False

# MyType: parse any type expression into an introspectable node.
t = MyType(dict[str, int])
t.main    # -> <class 'dict'>
t.args    # -> (MyType[str], MyType[int])
t.root    # -> dict[str, int]

ty is the package-wide Typist singleton -- cast/check/match chambers composed onto one object. See docs/ (built locally with task docs, or the hosted site once published) for the full subpackage tour: typing (this cast/check/match/MyType machinery), types, regex, caches, apis, utils, and files.

Modules

Utility Functions

Iteration Utilities

Syntax Utilities

Semantic Utilities

Text Utilities

Code Utilities

System Utilities

Logging
Profiling
Command Line Interaction
File System Validation

Enumerations

UUIDs

Environment Variables

Reusable Types

Minskian Predicates

Type Coercion

"Vibe" Typing

Text Processing

Regex "Stores"

Text Buffers

Markdown Trees

Typed Caches

File Caches

Nested Caches

Pickle Caches

Singleton Interfaces

GoogleSheets

Environment

Caveats

Pydantic-first

Although you can of course use this package without using Pydantic yourself, you'll be missing out on a lot of the ergonomic benefits: basically every class is a Pydantic "model", and the logging functionality included in my/base/utils.py exclusively supports Pydantic's Logfire.

Built for Python 3.12+

It would be pretty trivial to make this library work with versions as old as 3.11, and I aim to do this when I find the time. Anything older than that would be quite the reach however, as the typing code uses 3.11 syntax throughout a relatively complex module.

If you're blocked by this, either:

  1. Let me know!

  2. See if you can just manually extract the code you need from the repo. If you're only using one or two modules, it may be relatively trivial to backport the syntax.

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

my_basis-0.8.4.tar.gz (218.2 kB view details)

Uploaded Source

Built Distribution

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

my_basis-0.8.4-py3-none-any.whl (255.2 kB view details)

Uploaded Python 3

File details

Details for the file my_basis-0.8.4.tar.gz.

File metadata

  • Download URL: my_basis-0.8.4.tar.gz
  • Upload date:
  • Size: 218.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for my_basis-0.8.4.tar.gz
Algorithm Hash digest
SHA256 34932208a47166ec2cbcbb4a86b861326a7127da5ce2dff258f5b99dc949fef1
MD5 53ea609517513081c2b14fdaa9f1bff4
BLAKE2b-256 f7d8a73666ff1185cb7370ed03a05384074b1c077b286fd2ce2ff433d5ddcdae

See more details on using hashes here.

File details

Details for the file my_basis-0.8.4-py3-none-any.whl.

File metadata

  • Download URL: my_basis-0.8.4-py3-none-any.whl
  • Upload date:
  • Size: 255.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for my_basis-0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 614e8e855de275b842c972be12f0293ae4497e3901646571b4d75cbacd720048
MD5 460dbf9bb2c67649b246d425bef11b10
BLAKE2b-256 b109a58d328f6a5ec00e7e969de0022eb9da707b9fd2c26e4c61df14469836ef

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