Skip to main content

Changeless is a set of functions and objects to help convert your data into a set stateless or immutable data objects.

Types

from changeless.types import FancyHash, FancyModel, ImmutableHash, ImmutableModel

Fancy Types take a dict object and replaces the dereferencing operator ([]) with the dot operator. So the object

an_obj= FancyHash({"name":"me"})

will allow us to retrieve the attribute ‘name’ with

print "the object's name: " + an_obj.name
>the object's name: matt

Model Types take a Django ORM QueueSet and converts it to a comparable api. This uses the Fancy type as a base after converting the QuerySet to a dict. Foreign keys and many to many relationships are converted to nested dicts and lists of dicts(respectively) to aid in the objects behaving as similarly as possible.

Note that Model Types retrieve all of data at once which includes by default relationships directly adjacent. This might incur more queries than expected. Choose your data carefully and scale back when necessary.

  • FancyHash(a_dictonary)

  • FancyModel(a_model, depth=1)

  • ImmutableHash(a_dictonary)

  • ImmutableModel(a_model, depth=1)

Just pass the correct object into the type constructor to convert your data.

Decorators

from changeless.decorators import fancy_list

@fancy_list
def get_books():
    return Book.objects.all()

Place the following decorators before functions that return a Django ORM QueueSet to convert it to the correct changeless object. Decorators are the preferred way to use the changeless library. Using the decorators promote readability by keeping the conversion away from the ORM call, as well as providing an easy to way to turn the changeless conversion on and off. Notice that the _gen decorators will return a generator that will lazily convert each object in the list. Generators may be more efficient for long lists.

The following generators are available.
* fancy_list * fancy_gen * immutable_list * immutable_gen

Functions

I’ve found the following functions useful. ###fuzzyEquals### from changeless.compare import fuzzyEquals

i_obj = FancyHash({"name":'test name',
                   'sub_dict':{'name':'sub name', 'attrib':'sub attr value'}
                  })
second_i_obj = FancyHash({"name":'test name',
                          'sub_dict':{'name':'sub name', 'attrib':'sub attr value' }})
self.assertTrue( fuzzyEquals(
     i_obj,
     second_i_obj ))

fuzzyEquals will find attributes that the changeless objects have in common and compare only that union. This also inspects nested relationships for shared attributes. ###to_dict### from changeless.methods import to_dict to_dict is the reverse conversion from a base fancy_object to its dictionary representation.

Metadata

Release files for changeless 0.1.27

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

Source distribution (sdist)

Source distribution for changeless 0.1.27
File Size Uploaded
changeless-0.1.27.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for changeless 0.1.27
File Interpreter ABI Platform
changeless-0.1.27.macosx-10.8-intel.exe Details

Total release size: 84.5 kB

Release files / changeless-0.1.27.tar.gz

Download URL changeless-0.1.27.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0e9692626ce16f903fd4cba86b78863501290b8604bfef5d47a5b5ab137579ed
BLAKE2b-256 checksum
How to use checksums
bb84d666621dfca8bc406193202ba1ab7cb2c75d93e006feb1197d72b65f92a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / changeless-0.1.27.macosx-10.8-intel.exe

Download URL changeless-0.1.27.macosx-10.8-intel.exe
Size 76.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e9f5066bf041f24bc6b5f79cdb916428a772b7499c1557a50c698e1ab7eecd83
BLAKE2b-256 checksum
How to use checksums
27d209be3ba6ca6db2ce0cd1a0e5085da2309b26752a5d69600eaf577bf48d4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.27 This release

2 release files

0.1.26

2 release files

0.1.25

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.20

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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