np-ringbuffer


Namenp-ringbuffer JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryA module for ring buffer operations using NumPy backend
upload_time2023-10-12 09:21:25
maintainer
docs_urlNone
authorSee Leung
requires_python>=3.7
licenseMIT License Copyright (c) 2023 See Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ringbuffer timeseries numpy
VCS
bugtrack_url
requirements numpy
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # NP Ringbuffer

*np_ringbuffer* provides ring buffer operations using NumPy backend.

## Example usage
```python
from np_ringbuffer.ringbuffer import NumpyRingBuffer, TimedNumpyRingBuffer
import numpy as np

# construct from an existing numpy array
ringbuffer = NumpyRingBuffer.create_from_array(np.array([1,2,3]))
ringbuffer.append(3)
print(ringbuffer.values())  # [2,3,3]
ringbuffer.add_to_latest(10)
print(ringbuffer.values()) # [2,3,13]

# construct an empty buffer with 5 capacity
ringbuffer = NumpyRingBuffer(capacity=10)
ringbuffer.append(3)
print(ringbuffer.values())  # [3]
ringbuffer.add_to_latest(10)
print(ringbuffer.values()) # [13]

# automate the append and add_to_latest with interval_ms
timed_ringbuffer = TimedNumpyRingBuffer(interval_ms=60_000, capacity=10)
timed_ringbuffer.add(1)

```

### Practical usuage
In finance, if you want to build an real-time trading volume accumulator in 1-minute bucket. You can do something like this (this example uses 1-second bar for simplicity sake):

```python
# volume 1-second bar example
def generate_volume() -> float:
    return random.random() * 100

def get_volume(iterations: int = 1_000_000, pause_ms: float = 1e-5):
    for _ in range(iterations):
        time.sleep(pause_ms)
        yield generate_volume()

timed_ringbuffer = TimedNumpyRingBuffer(interval_ms=1000, capacity=10)
for volume in get_volume():
    timed_ringbuffer.add(volume)
print(timed_ringbuffer.values())
```

All of these examples are included in example.py

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "np-ringbuffer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "ringbuffer,timeseries,numpy",
    "author": "See Leung",
    "author_email": "See Leung <sleung852@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/69/64/1f9fe43f6b71a7ae3321cecb9ae505f31dc89889f85b47dd847e375750a1/np_ringbuffer-1.0.0.tar.gz",
    "platform": null,
    "description": "# NP Ringbuffer\n\n*np_ringbuffer* provides ring buffer operations using NumPy backend.\n\n## Example usage\n```python\nfrom np_ringbuffer.ringbuffer import NumpyRingBuffer, TimedNumpyRingBuffer\nimport numpy as np\n\n# construct from an existing numpy array\nringbuffer = NumpyRingBuffer.create_from_array(np.array([1,2,3]))\nringbuffer.append(3)\nprint(ringbuffer.values())  # [2,3,3]\nringbuffer.add_to_latest(10)\nprint(ringbuffer.values()) # [2,3,13]\n\n# construct an empty buffer with 5 capacity\nringbuffer = NumpyRingBuffer(capacity=10)\nringbuffer.append(3)\nprint(ringbuffer.values())  # [3]\nringbuffer.add_to_latest(10)\nprint(ringbuffer.values()) # [13]\n\n# automate the append and add_to_latest with interval_ms\ntimed_ringbuffer = TimedNumpyRingBuffer(interval_ms=60_000, capacity=10)\ntimed_ringbuffer.add(1)\n\n```\n\n### Practical usuage\nIn finance, if you want to build an real-time trading volume accumulator in 1-minute bucket. You can do something like this (this example uses 1-second bar for simplicity sake):\n\n```python\n# volume 1-second bar example\ndef generate_volume() -> float:\n    return random.random() * 100\n\ndef get_volume(iterations: int = 1_000_000, pause_ms: float = 1e-5):\n    for _ in range(iterations):\n        time.sleep(pause_ms)\n        yield generate_volume()\n\ntimed_ringbuffer = TimedNumpyRingBuffer(interval_ms=1000, capacity=10)\nfor volume in get_volume():\n    timed_ringbuffer.add(volume)\nprint(timed_ringbuffer.values())\n```\n\nAll of these examples are included in example.py\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 See  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A module for ring buffer operations using NumPy backend",
    "version": "1.0.0",
    "project_urls": {
        "Home": "https://github.com/sleung852/np_ringbuffer"
    },
    "split_keywords": [
        "ringbuffer",
        "timeseries",
        "numpy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b2b272b081f97988f856c1f4551df50637755b6a433224efc8693d859ecef9e1",
                "md5": "ea39b803c6ed2bb01407c866ab5d5666",
                "sha256": "409a2c6c2f149b65a192338159bfa3635762824780c0dc5f918d19dfbbc181fc"
            },
            "downloads": -1,
            "filename": "np_ringbuffer-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea39b803c6ed2bb01407c866ab5d5666",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4447,
            "upload_time": "2023-10-12T09:21:24",
            "upload_time_iso_8601": "2023-10-12T09:21:24.498483Z",
            "url": "https://files.pythonhosted.org/packages/b2/b2/72b081f97988f856c1f4551df50637755b6a433224efc8693d859ecef9e1/np_ringbuffer-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "69641f9fe43f6b71a7ae3321cecb9ae505f31dc89889f85b47dd847e375750a1",
                "md5": "4fd01e7ba5371d48053aa075f784abaa",
                "sha256": "0619bdee8b8ebb42011a210a4d72a7f816785f4129910a0396063f20c205c115"
            },
            "downloads": -1,
            "filename": "np_ringbuffer-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4fd01e7ba5371d48053aa075f784abaa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4438,
            "upload_time": "2023-10-12T09:21:25",
            "upload_time_iso_8601": "2023-10-12T09:21:25.989694Z",
            "url": "https://files.pythonhosted.org/packages/69/64/1f9fe43f6b71a7ae3321cecb9ae505f31dc89889f85b47dd847e375750a1/np_ringbuffer-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-12 09:21:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sleung852",
    "github_project": "np_ringbuffer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.0"
                ]
            ]
        }
    ],
    "lcname": "np-ringbuffer"
}
        
Elapsed time: 0.76240s