choose
========
Choices on steroids
.. image:: https://img.shields.io/pypi/v/choose.svg
:target: https://pypi.python.org/pypi/choose
.. image:: https://img.shields.io/travis/ulamlabs/choose.svg
:target: https://travis-ci.org/ulamlabs/choose
.. image:: https://codecov.io/gh/ulamlabs/choose/branch/master/graph/badge.svg
:target: https://codecov.io/gh/ulamlabs/choose
Supported versions
================
- Python 2 and 3 support
How to install
==========
.. code-block:: bash
pip install choose
Basic usage:
===========
.. code-block:: python
>>> class Types(choose.Choices):
>>> BAR = choose.Choice('foo_bar', 'Foo Bar')
>>> BAZ = choose.Choice('foo_baz', 'Foo Baz')
>>> Types.BAR
'foo_bar'
>>> Types.BAR.text
'Foo Bar'
>>> Types.items()
(('foo_bar', 'Foo Bar'), ('foo_baz', 'Foo Baz'))
>>> Types.keys()
('foo_bar', 'foo_baz')
>>> Types.values()
('Foo Bar', 'Foo Baz')
>>> 'foo_bar' in Types
True
Extended usage:
===============
.. code-block:: python
>>> class Types2(choose.Choices):
>>> BAR = choose.Choice('foo_bar', 'Foo Bar', default=False)
>>> BAZ = choose.Choice('foo_baz', 'Foo Baz', default=False)
>>> FOO = choose.Choice('foo_foo', 'Foo Foo', default=True)
>>>
>>> @classmethod
>>> def get_default(cls):
>>> return next(
>>> (item for item in cls.keys() if item.opts.default is True),
>>> None,
>>> )
>>>
>>> Types2.BAR.opts.default
False
>>> Types2.BAR.opts.not_existing_attr is None
True
>>> 'foo_bar' == Types2.get_default()
False
>>> Types2.BAR == Types2.get_default()
False
>>> 'foo_foo' == Types2.get_default()
True
>>> Types2.FOO == Types2.get_default()
True
Usage in Django:
================
.. code-block:: python
class AModel(models.Model):
class AChoices(choose.Choices):
X = choose.Choice('x', 'X')
Y = choose.Choice('y', 'Y')
choice = models.CharField(max_length=63, choices=AChoices.items())
========
Choices on steroids
.. image:: https://img.shields.io/pypi/v/choose.svg
:target: https://pypi.python.org/pypi/choose
.. image:: https://img.shields.io/travis/ulamlabs/choose.svg
:target: https://travis-ci.org/ulamlabs/choose
.. image:: https://codecov.io/gh/ulamlabs/choose/branch/master/graph/badge.svg
:target: https://codecov.io/gh/ulamlabs/choose
Supported versions
================
- Python 2 and 3 support
How to install
==========
.. code-block:: bash
pip install choose
Basic usage:
===========
.. code-block:: python
>>> class Types(choose.Choices):
>>> BAR = choose.Choice('foo_bar', 'Foo Bar')
>>> BAZ = choose.Choice('foo_baz', 'Foo Baz')
>>> Types.BAR
'foo_bar'
>>> Types.BAR.text
'Foo Bar'
>>> Types.items()
(('foo_bar', 'Foo Bar'), ('foo_baz', 'Foo Baz'))
>>> Types.keys()
('foo_bar', 'foo_baz')
>>> Types.values()
('Foo Bar', 'Foo Baz')
>>> 'foo_bar' in Types
True
Extended usage:
===============
.. code-block:: python
>>> class Types2(choose.Choices):
>>> BAR = choose.Choice('foo_bar', 'Foo Bar', default=False)
>>> BAZ = choose.Choice('foo_baz', 'Foo Baz', default=False)
>>> FOO = choose.Choice('foo_foo', 'Foo Foo', default=True)
>>>
>>> @classmethod
>>> def get_default(cls):
>>> return next(
>>> (item for item in cls.keys() if item.opts.default is True),
>>> None,
>>> )
>>>
>>> Types2.BAR.opts.default
False
>>> Types2.BAR.opts.not_existing_attr is None
True
>>> 'foo_bar' == Types2.get_default()
False
>>> Types2.BAR == Types2.get_default()
False
>>> 'foo_foo' == Types2.get_default()
True
>>> Types2.FOO == Types2.get_default()
True
Usage in Django:
================
.. code-block:: python
class AModel(models.Model):
class AChoices(choose.Choices):
X = choose.Choice('x', 'X')
Y = choose.Choice('y', 'Y')
choice = models.CharField(max_length=63, choices=AChoices.items())
Metadata
Release files for choose 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| choose-2.0.0.tar.gz | 2.8 kB | Without provenance | Details |
Release files / choose-2.0.0.tar.gz
| Download URL | choose-2.0.0.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f76cca6b36f2fe5410ad19af5820f13497cfc3e46dbf4cd93a91152371d36744
|
|
BLAKE2b-256 checksum How to use checksums |
f6cea8bb6d21461b34c0782307fa401389b90649b4ac4b2f23fbb926266cd438
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for choose 2.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.