Skip to main content

No project description provided

Project description

UPTo

UPTo - A personal collection of potentially generally Useful Python Tools.

ComposeRouter

The ComposeRouter class allows to route attributes access for registered methods through a functional pipeline constructed from components. The pipeline is only triggered if a registered method is accessed via the ComposeRouter namespace.

from upto import ComposeRouter

class Foo:
	route = ComposeRouter(lambda x: x + 1, lambda y: y * 2)

	@route.register
	def method(self, x, y):
		return x * y

    foo = Foo()

print(foo.method(2, 3))           # 6
print(foo.route.method(2, 3))     # 13

CurryModel

The CurryModel constructor allows to sequentially initialize (curry) a Pydantic model.

from upto import CurryModel

class MyModel(BaseModel):
    x: str
    y: int
    z: tuple[str, int]


curried_model = CurryModel(MyModel)

curried_model(x="1")
curried_model(y=2)

model_instance = curried_model(z=("3", 4))
print(model_instance)

CurryModel instances are recursive so it is also possible to do this:

curried_model_2 = CurryModel(MyModel)
model_instance_2 = curried_model_2(x="1")(y=2)(z=("3", 4))
print(model_instance_2)

Currying turns a function of arity n into at most n functions of arity 1 and at least 1 function of arity n (and everything in between), so you can also do e.g. this:

curried_model_3 = CurryModel(MyModel)
model_instance_3 = curried_model_3(x="1", y=2)(z=("3", 4))
print(model_instance_3)

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

upto-0.1.0.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

upto-0.1.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file upto-0.1.0.tar.gz.

File metadata

  • Download URL: upto-0.1.0.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.7-arch1-2

File hashes

Hashes for upto-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0085ec3a06ff1b74a0ecb7bdc0964aa8823d23de727406cf6fac31ae7f8f8f1e
MD5 1361fe3aae078163a5306da79be71621
BLAKE2b-256 1993a3d3be6335a692479b2fdad415267ce4308bbd458bd62984a73e3d99e393

See more details on using hashes here.

File details

Details for the file upto-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: upto-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.7-arch1-2

File hashes

Hashes for upto-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f8db82edc4f1464243fa7e41c35447c90d2fb0e18f8250b54ca4eb0804c3ae1
MD5 df0408535acb31275dc703c8f4da6686
BLAKE2b-256 3355de1dfeaf3e3cd3651e8e616efad2b573b1c7dfc0e6cbf3c1e0fc67a15a7a

See more details on using hashes here.

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