HashIDTools
===========
.. image:: https://travis-ci.org/joeblackwaslike/hashidtools.svg?branch=master
:target: https://travis-ci.org/joeblackwaslike/hashidtools
:alt: Build Status
.. image:: https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat
:target: https://github.com/joeblackwaslike/hashidtools
:alt: Github Repo
.. image:: https://img.shields.io/pypi/v/hashidtools.svg
:target: https://pypi.python.org/pypi/hashidtools
:alt: Pypi Version
.. image:: https://img.shields.io/pypi/l/hashidtools.svg
:target: https://pypi.python.org/pypi/hashidtools
:alt: Pypi License
.. image:: https://img.shields.io/pypi/wheel/hashidtools.svg
:target: https://pypi.python.org/pypi/hashidtools
:alt: Pypi Wheel
.. image:: https://img.shields.io/pypi/pyversions/hashidtools.svg
:target: https://pypi.python.org/pypi/hashidtools
:alt: Pypi Versions
Maintainer
----------
Joe Black | me@joeblack.nyc | `github <https://github.com/joeblackwaslike>`_
Introduction
------------
HashID tools/components for async ID generation. Example: ``k62K3zOn4Y5Kkxmg7pWOAqPyd8NVjrmX`` Designed for async data model ID generation for persisting objects to a graph DB such as ZODB. ZCA means it's simple to customize and override without editing any code.
Comes with
~~~~~~~~~~
* Customizable Generator/encoder/decoder utility
* Type class (experimental)
* Persistent, 2x BTree-powered IntID/Ref Manager
* Custom fields for ``zope.schema`` and ``attrs``\ , with default factory functions, validation, etc.
Also
~~~~
* Random seed integer is just under 64bits.
* Derive seed integer at any time by casting type as an int.
Installation
------------
.. code-block:: shell
pip3 install hashidtools
Usage
-----
HashIDGenerator
^^^^^^^^^^^^^^^
.. code-block:: python
>>> from hashidtools import HashIDGenerator
>>> gen = HashIDGenerator(salt='my random salt', min_length=32)
>>> gen.seed()
...
>>> gen
HashIDGenerator(salt='my random salt', min_length=32)
>>> gen.new()
'...'
>>> gen.decode(gen.new())
...
HashID Type
^^^^^^^^^^^
.. code-block:: python
>>> from hashidtools import HashID
... HashID()
'...'
>>> HashID('8nKqkABjlYB5A7430M917zAJao1Me4mN')
'8nKqkABjlYB5A7430M917zAJao1Me4mN'
Hashid IntID Indexing & Event System
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> intid = HashIDManager()
... intid
HashIDManager(attribute='id')
... intid.generateId()
'...'
>>> from zc.intid.interfaces import AddedEvent, RemovedEvent
... import zope.event.classhandler
...
>>> @zope.event.classhandler.handler(AddedEvent)
... def handler(event):
... print(event.id, event.object, event.idmanager)
...
... @zope.event.classhandler.handler(RemovedEvent)
... def handler(event):
... print(event.id, event.object, event.idmanager)
>>> import attr
... Test = attr.make_class(
... 'Test', {'id': fields.hashid(init=False),
... 'name': attr.ib(default='default-name')})
...
>>> t = Test()
... intid.register(t)
'...'
... id = intid.getId(t)
... intid.getObject(id)
Test(id='...', name='default-name')
>>> intid.unregister(t)
Retrieving the utilities through the ZCA Registry
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
>>> from zope.component import queryUtility
... from hashidtools.interfaces import IHashIDGenerator, IIntIds
...
... queryUtility(IHashIDGenerator)
HashIDGenerator(salt='$2a$12$AAAAAAAAAAAAAACgpDEPGQ', min_length=32)
>>> queryUtility(IIntIds)
HashIDs(attribute='id')
Extending this Package
^^^^^^^^^^^^^^^^^^^^^^
This package uses Zope Component Architecture for the ultimate in pluggable extendibility.
Quick example of customizing the HashID Generator:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
# Note: you can also create your own Generator class that implements the
# IHashIDGenerator interface and register it.
from zope.component import provideUtility
from hashidtools import HashIDGenerator
from hashidtools.interfaces import IHashIDGenerator
generator = HashIDGenerator(**custom_options)
provideUtility(generator, IHashIDGenerator)
Note: the following would preferrably be done using your project's ZCML directives.
Changes
-------
* `CHANGELOG <CHANGELOG.md>`_
Metadata
Release files for hashidtools 1.0.2
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 | Actions |
|---|---|---|---|---|
| hashidtools-1.0.2.tar.gz | 9.9 kB | Without provenance | Details for hashidtools-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hashidtools-1.0.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for hashidtools-1.0.2-py2.py3-none-any.whl |
Total release size: 21.2 kB
Release files / hashidtools-1.0.2.tar.gz
| Download URL | hashidtools-1.0.2.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a14f788e615fbec0588a6aebce4627f52d7547ac000863f8123392a333cc93db
|
|
BLAKE2b-256 checksum How to use checksums |
6f708fe3b2aa26ae1a5e466b0603629506d778b47e948e9b104f22063fd54fc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / hashidtools-1.0.2-py2.py3-none-any.whl
| Download URL | hashidtools-1.0.2-py2.py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
48f3cca2c8b5e4e1ef06ec32ea34a04612d8bb9511a267c08bb40783e736ae75
|
|
BLAKE2b-256 checksum How to use checksums |
8a1669f51cb5702fe74cc9854307c8098c0cafeb858e305095e37987cc84b16d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for hashidtools 1.0.2
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.