![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Map options/flags to methods using 32 or 64bit integers for optimized state management.
A lightweight Python package for efficient settings management and manipulation. Easily handle language preferences, settings, and other flag-based configurations using minimal memory.
Install using pip
:
pip install tiny_flags
Requires OrderedDict
from collections import OrderedDict
from tiny_flags import TinyFlags
fields = OrderedDict([
('language', ['english', 'spanish', 'french']), # Uses 2 bits, might make sense to add even number and mark the last as '_option'
('dark_mode', False), # Uses 1 bit, initial value
('notifications', True) # Uses 1 bit, initial value
])
You can easily create your settings structure by looking at the below example. One should think ahead before implementing the structure of the ordered dictionary and it might make sense to reserve some extra for the list options for later use. NOTE!: The order matters and changing it later can create some issues in migrating to a new structure. Think ahead in what you need, don't remove rather just add. If you don't need an option then perhaps leave it and rename with _ prefix, and just ignore it. Boolean flags are easy, it is just True or False, but the list options take up the same space whether odd or even number of items given. It might make sense for you to add the last option in such list and use _ prefix as for deprecated options mentioned above. Booleans use 1 bit position, and option list uses 1 bit position for every 2 items (even with 1 item 1 bit position is reserved, so be careful about odd numbers)
manager = TinyFlags(fields)
Default value is 32bit, but give True for 64bit, TinyFlags(fields, True)
. Check that your environment supports 64bit integers before trying to use them.
manager.set_value('language', 'spanish')
For options lists just select the category first followed by the option you wish to set.
manager.set_value('dark_mode', True)
For boolean flags, just use the key and give True/False
to enable/disable.
print(manager.get_value('language')) # 'spanish'
print(manager.get_value('dark_mode')) # True
print(manager.get_value('notifications')) # True
When using a database there are of course drawbacks on using a bitfield for settings for example if you need complex queries on the bits then put them in their own columns. If you need to do complex queries on the settings, for those kinds of settings it is not the best solution. Indexing will index the full integer not the individual bits. Changing settings later might be cumbersome, but if popularity picks up I can add a migration tool or if you have pioneering spirit please contribute.
Setup Development Environment & clone the repository
git clone https://github.com/FistOfTheNorthStar/tiny_flags
cd tiny_flags
Install pip install -e .
Running Tests pytest tests/
There is also a dev_lint.sh
script lints and installs the development version. Check it out if you are interested.
Contributions are welcome.
Distributed under the MIT License. See LICENSE for more information.
Add more option mappings possibilities See if 32/64bit values should have a forced type Test with actual DB (MongoDB 32/64 bit ints)
FAQs
Map options/flags to methods using 32 or 64bit integers for optimized state management.
We found that tiny-flags demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.