Skip to main content

Refrax

Refrax is a small, pragmatic library implementing the optics pattern for JAX PyTrees.

It focuses on elegant syntax and composable conditional chains to provide easy yet powerful PyTree manipulation.

Installation

Refrax can be installed using pip:

pip install refrax

Quick example

import equinox as eqx
import jax

class Model(eqx.Module):
    core: eqx.nn.Linear
    head: eqx.nn.Linear
    dropout: float

key1, key2 = jax.random.split(jax.random.key(0))
model = Model(
    core=eqx.nn.Linear(in_features=5, out_features=5, key=key1),
    head=eqx.nn.Linear(in_features=5, out_features=2, key=key2),
    dropout=0.5
)

Then we can do updates using focus:

from refrax import focus

model = focus(model).dropout.set(0.1)
model = focus(model).select("core", "head").bias.apply(lambda b: b + 1.0)

model.dropout
# 0.1

model.core.bias
# [0.646, 0.860, 0.670 , 1.277 , 0.727]

model.head.bias
# [1.634, 1.877]

One of the useful optics methods is simply traversing over a PyTree's leaves:

len(focus(model).leaves().get())
# 5

Documentation

Documentation is available here.

Related

The library uses Equinox (specifically eqx.tree_at) under the hood.

Metadata

Release files for refrax 0.0.6

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

Source distribution (sdist)

Source distribution for refrax 0.0.6
File Size Uploaded Provenance Actions
refrax-0.0.6.tar.gz 21.3 kB With provenance Details for refrax-0.0.6.tar.gz

Built distribution (wheel)

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

Total release size: 34.2 kB

Release files / refrax-0.0.6.tar.gz

Download URL refrax-0.0.6.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f5090adda4c37d619005854c4254c27bad9fcbbd926fb13861f4dc8c64c87b01
BLAKE2b-256 checksum
How to use checksums
322711b6e22ca97c0901647c20a8f1c351dedd4638d8bb1a52e078347212f073
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release files / refrax-0.0.6-py3-none-any.whl

Download URL refrax-0.0.6-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94f20b96d0bc35b1ca52c3eabb858df84b55d9397e77dbef68325deba1b8cf36
BLAKE2b-256 checksum
How to use checksums
8b13e5099e033d55b3c9614165c5414f78e6d213adbc9bb42a67413b3e77a64d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Security for refrax 0.0.6

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for refrax-0.0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

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