Skip to main content
https://travis-ci.org/MacHu-GWU/constant-project.svg?branch=master https://img.shields.io/pypi/v/constant.svg https://img.shields.io/pypi/l/constant.svg https://img.shields.io/pypi/pyversions/constant.svg

Welcome to constant Documentation

If you have lots of constant value widely used across your development. A better way is to define Constant Variable rather than using the raw value. This will improve the readability of your codes.

constant is a library provide extensive way of managing your constant.

Example:

from constant import Constant
from constant.pkg.sixmini import PY3


class Food(Constant):

    class Fruit(Constant):
        id = 1
        name = "fruit"

        class Apple(Constant):
            id = 1
            name = "apple"

            class RedApple(Constant):
                id = 1
                name = "red apple"

            class GreenApple(Constant):
                id = 2
                name = "green apple"

        class Banana(Constant):
            id = 2
            name = "banana"

            class YellowBanana(Constant):
                id = 1
                name = "yellow banana"

            class GreenBanana(Constant):
                id = 2
                name = "green banana"

    class Meat(Constant):
        id = 2
        name = "meat"

        class Pork(Constant):
            id = 1
            name = "pork"

        class Meat(Constant):
            id = 2
            name = "meat"

You can visit it’s data or child class data in these way.

>>> Fruit.items() # .items() return it's data
[('id', 1), ('name', 'fruit')]

>>> Fruit.keys() # .keys() return keys
['id', 'name']

>>> Fruit.keys() # .values() return values
[1, 'fruit']

>>> Fruit.to_dict() # return data in a dict
{'id': 1, 'name': 'fruit'}

# iterate on all child class
>>> Fruit.collection(sort_by='id')
[class Apple, class Banana]

# get first child class that kls.id == 1
# useful when you need reverse lookup
>>> Fruit.get('id', 1)
class Apple

>>> Fruit.get('id', 1, multi=True) # get all child class that kls.id == 1
[class Apple, ]

Install

constant is released on PyPI, so all you need is:

$ pip install constant

To upgrade to latest version:

$ pip install --upgrade constant

Metadata

Release files for constant 0.0.4

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

Source distribution (sdist)

Source distribution for constant 0.0.4
File Size Uploaded
constant-0.0.4.zip 63.5 kB Details

Release files / constant-0.0.4.zip

Download URL constant-0.0.4.zip
Size 63.5 kB
Tags Source
SHA-256 checksum
How to use checksums
be9b89b553e2cd9440598442a23bf2c538f5d0d852ce17be5494b01d351f1a0b
BLAKE2b-256 checksum
How to use checksums
2573c272439718f93933e10da7e0502752b9c349c8bebe0ed2df14e618838bb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.4 This release

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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