Skip to main content

Nubby

A simple config loader for Python using Bevy for dependency injection. You just need to create a model, declare what file name it should look for, and mark that model as a dependency wherever you need to have it made available.

Installation

pip install nubby

You can optionally install the toml or yaml extras to support those file formats.

pip install nubby[toml]
pip install nubby[yaml]

Out of the box Nubby will use tomllib to read TOML files but the toml extra installs the tomlkit package which allows writing to TOML files.

Usage

Nubby is designed to have the smallest possible API surface area. You just need to create a model type that implements the SectionModel interface and declare the file name it should look for. Then you can inject that model wherever you need it using Bevy.

The file name shouldn't include the file extension. Nubby's file handlers look for supported file extensions in the search paths. By default, the current working directory is the only search path. You can add more paths using the nubby.get_active_controller().add_path method. It is also possible to add more file handlers using the nubby.get_active_controller().add_handler method.

Here's a basic example of loading a model from a file:

from dataclasses import dataclass
from bevy import inject, dependency
from nubby.models import new_file_model


file_definition = new_file_model("person_info")

@file_definition.section("person")
@dataclass
class Person:
    name: str
    age: int


@inject
def print_person_details(person: Person = dependency()):
    print(f"{person.name} is {person.age} years old")

Running print_person_details() prints the name and age of the person loaded from the person section of the person_info file. Depending on the available file handlers it could be a json, toml, or yaml file.

Note that it is not necessary to pass anything to the print_person_details function. Nubby uses Bevy to automatically inject the Person model and loads the appropriate config file.

To save any modifications to a model just call the active controller's save method, passing it the updated model:

from nubby import get_active_controller

# After modifying the person model
person.age = 32
get_active_controller().save(person)

The save method will update the in-memory cache as well as the file on disk. It will not update any models that have already been created.

Name Normalization

By default, section names in config files match the class name. You can customize this behavior:

# Use snake_case for section names
file_definition = new_file_model("config", generate_normalized_names=True)

@file_definition.section()  # Will use "user_profile" as the section name key in the config file
@dataclass
class UserProfile:
    username: str
    email: str

Supported File Formats

Nubby supports the following file formats out of the box:

  • JSON (.json)
  • TOML (.toml) - requires tomlkit for writing
  • YAML (.yaml, .yml) - requires pyyaml

License

Nubby is made available under the MIT License.

Metadata

Release files for nubby 0.1.2

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

Source distribution (sdist)

Source distribution for nubby 0.1.2
File Size Uploaded
nubby-0.1.2.tar.gz 12.4 kB Details

Built distribution (wheel)

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

Total release size: 26.1 kB

Release files / nubby-0.1.2.tar.gz

Download URL nubby-0.1.2.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2fd610430b48d9a3f16a4f80401c9fbad3071f820b0de1fe6ec49d3e3aa555bb
BLAKE2b-256 checksum
How to use checksums
ecbdc4824eeffa72afb0f100328e5de421d6e7c1ae4e49ca0aed301b5c6c9979
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.6.9

Release files / nubby-0.1.2-py3-none-any.whl

Download URL nubby-0.1.2-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b7d20e387771559cd6a5202fd476d9336328dbbb5d4872a316fbf85a9031aa3
BLAKE2b-256 checksum
How to use checksums
a8ebdb697ae7b96094e3ce46b6361465bd0578805a27f68b9cbd2d91b83915bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.6.9

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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