motion-lake-client


Namemotion-lake-client JSON
Version 0.0.15 PyPI version JSON
download
home_pageNone
SummaryMotion Lake Client, a client for the Motion Lake API (a Mobility Data Lake)
upload_time2024-05-01 16:52:27
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseAll Rights Reserved Copyright (c) 2024 Gaspard Merten 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 motion-lake mobility data api client
VCS
bugtrack_url
requirements certifi charset-normalizer idna requests urllib3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MotionLake Client

MotionLake Client is a Python client library for interacting with a storage server designed for a new mobility data lake
solution. It provides functionalities to create collections, store data, query data, and retrieve collections.

## Installation

You can install the library via pip:

```bash
pip install motion-lake-client
```

## Usage

Here's a brief overview of how to use the library:

```python
from motion_lake_client import BaseClient

# Initialize the client with the base URL of the storage server
client = BaseClient(lake_url="http://localhost:8000")

# Create a new collection
client.create_collection("my_collection")

# Store data in a collection
data = b"example_data"
timestamp = int(datetime.now().timestamp())
client.store("my_collection", data, timestamp)

# Query data from a collection
results = client.query(
    "my_collection", min_timestamp=0, max_timestamp=timestamp, ascending=True
)

# Retrieve last item from a collection
last_item = client.get_last_item("my_collection")

# Retrieve first item from a collection
first_item = client.get_first_item("my_collection")

# Get items between two timestamps
items_between = client.get_items_between(
    "my_collection", min_timestamp=0, max_timestamp=timestamp
)

# Get items before a timestamp
items_before = client.get_items_before("my_collection", timestamp, limit=10)

# Get items after a timestamp
items_after = client.get_items_after("my_collection", timestamp, limit=10)

# Get all collections
collections = client.get_collections()

```

## Documentation

The library provides a series of classes and methods for storing, querying, and managing collections of data items. Each
item is timestamped and can be stored in various formats. Below is a detailed usage guide for each component provided by
the API.

### Prerequisites

Before using the API, make sure you have the `requests` library installed:

```bash
pip install requests
```

### Initializing the Client

To start interacting with the data storage server, instantiate the `BaseClient` with the URL of the storage server:

```python
from datetime import datetime
from my_module import BaseClient, ContentType

# Initialize the client; replace 'http://localhost:8000' with your server's URL
client = BaseClient('http://localhost:8000')
```

### Creating a Data Collection

Create a new data collection by specifying its name:

```python
response = client.create_collection("weather_data")
print(response)
```

### Storing Data

Store data in a specified collection:

```python
data = b"Example data"
timestamp = datetime.now()

# Store data as raw bytes
response = client.store("weather_data", data, timestamp, ContentType.RAW)
print(response)
```

You can also specify whether to create the collection if it doesn't exist:

```python
response = client.store("weather_data", data, timestamp, ContentType.JSON, create_collection=True)
print(response)
```

### Querying Data

Retrieve items from a collection based on various criteria:

- **Query by Timestamp Range**:
  ```python
  from datetime import datetime, timedelta

  start_date = datetime.now() - timedelta(days=1)
  end_date = datetime.now()

  items = client.get_items_between("weather_data", start_date, end_date)
  for item in items:
      print("Timestamp:", item.timestamp, "Data:", item.data)
  ```

- **Get Last N Items**:
  ```python
  last_items = client.get_last_items("weather_data", 5)
  for item in last_items:
      print("Timestamp:", item.timestamp, "Data:", item.data)
  ```

- **Get First N Items**:
  ```python
  first_items = client.get_first_items("weather_data", 5)
  for item in first_items:
      print("Timestamp:", item.timestamp, "Data:", item.data)
  ```
  
- **Get Items but skip data (only load timestamps)**:
  ```python
  first_items = client.get_first_items("weather_data", 5, skip_data=True)
  for item in first_items:
      print("Timestamp:", item.timestamp)
      assert item.data is None, "Data should be None, otherwise developer made a mistake (aka me)" 
  ```

### Advanced Queries

Perform an advanced SQL-like query (make sure your query string contains the placeholder `[table]`):

```python
query = "SELECT * FROM [table] WHERE data LIKE '%sample%'"
min_timestamp = datetime(2023, 1, 1)
max_timestamp = datetime(2023, 1, 31)

response = client.advanced_query("weather_data", query, min_timestamp, max_timestamp)
print(response)
```

### Managing Collections

- **List All Collections**:
  ```python
  collections = client.get_collections()
  for collection in collections:
      print(f"Collection: {collection.name}, Items: {collection.count}")
  ```

- **Delete a Collection**:
  ```python
  response = client.delete_collection("weather_data")
  print(response)
  ```


## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.

## License

All rights reserved.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "motion-lake-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "motion-lake, mobility, data, api, client",
    "author": null,
    "author_email": "Gaspard Merten <gaspard.mp.work@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ee/c3/6cd674596cdcd65b4ab394e1d4e807dca33807c1605f9747ce7c85506014/motion_lake_client-0.0.15.tar.gz",
    "platform": null,
    "description": "# MotionLake Client\n\nMotionLake Client is a Python client library for interacting with a storage server designed for a new mobility data lake\nsolution. It provides functionalities to create collections, store data, query data, and retrieve collections.\n\n## Installation\n\nYou can install the library via pip:\n\n```bash\npip install motion-lake-client\n```\n\n## Usage\n\nHere's a brief overview of how to use the library:\n\n```python\nfrom motion_lake_client import BaseClient\n\n# Initialize the client with the base URL of the storage server\nclient = BaseClient(lake_url=\"http://localhost:8000\")\n\n# Create a new collection\nclient.create_collection(\"my_collection\")\n\n# Store data in a collection\ndata = b\"example_data\"\ntimestamp = int(datetime.now().timestamp())\nclient.store(\"my_collection\", data, timestamp)\n\n# Query data from a collection\nresults = client.query(\n    \"my_collection\", min_timestamp=0, max_timestamp=timestamp, ascending=True\n)\n\n# Retrieve last item from a collection\nlast_item = client.get_last_item(\"my_collection\")\n\n# Retrieve first item from a collection\nfirst_item = client.get_first_item(\"my_collection\")\n\n# Get items between two timestamps\nitems_between = client.get_items_between(\n    \"my_collection\", min_timestamp=0, max_timestamp=timestamp\n)\n\n# Get items before a timestamp\nitems_before = client.get_items_before(\"my_collection\", timestamp, limit=10)\n\n# Get items after a timestamp\nitems_after = client.get_items_after(\"my_collection\", timestamp, limit=10)\n\n# Get all collections\ncollections = client.get_collections()\n\n```\n\n## Documentation\n\nThe library provides a series of classes and methods for storing, querying, and managing collections of data items. Each\nitem is timestamped and can be stored in various formats. Below is a detailed usage guide for each component provided by\nthe API.\n\n### Prerequisites\n\nBefore using the API, make sure you have the `requests` library installed:\n\n```bash\npip install requests\n```\n\n### Initializing the Client\n\nTo start interacting with the data storage server, instantiate the `BaseClient` with the URL of the storage server:\n\n```python\nfrom datetime import datetime\nfrom my_module import BaseClient, ContentType\n\n# Initialize the client; replace 'http://localhost:8000' with your server's URL\nclient = BaseClient('http://localhost:8000')\n```\n\n### Creating a Data Collection\n\nCreate a new data collection by specifying its name:\n\n```python\nresponse = client.create_collection(\"weather_data\")\nprint(response)\n```\n\n### Storing Data\n\nStore data in a specified collection:\n\n```python\ndata = b\"Example data\"\ntimestamp = datetime.now()\n\n# Store data as raw bytes\nresponse = client.store(\"weather_data\", data, timestamp, ContentType.RAW)\nprint(response)\n```\n\nYou can also specify whether to create the collection if it doesn't exist:\n\n```python\nresponse = client.store(\"weather_data\", data, timestamp, ContentType.JSON, create_collection=True)\nprint(response)\n```\n\n### Querying Data\n\nRetrieve items from a collection based on various criteria:\n\n- **Query by Timestamp Range**:\n  ```python\n  from datetime import datetime, timedelta\n\n  start_date = datetime.now() - timedelta(days=1)\n  end_date = datetime.now()\n\n  items = client.get_items_between(\"weather_data\", start_date, end_date)\n  for item in items:\n      print(\"Timestamp:\", item.timestamp, \"Data:\", item.data)\n  ```\n\n- **Get Last N Items**:\n  ```python\n  last_items = client.get_last_items(\"weather_data\", 5)\n  for item in last_items:\n      print(\"Timestamp:\", item.timestamp, \"Data:\", item.data)\n  ```\n\n- **Get First N Items**:\n  ```python\n  first_items = client.get_first_items(\"weather_data\", 5)\n  for item in first_items:\n      print(\"Timestamp:\", item.timestamp, \"Data:\", item.data)\n  ```\n  \n- **Get Items but skip data (only load timestamps)**:\n  ```python\n  first_items = client.get_first_items(\"weather_data\", 5, skip_data=True)\n  for item in first_items:\n      print(\"Timestamp:\", item.timestamp)\n      assert item.data is None, \"Data should be None, otherwise developer made a mistake (aka me)\" \n  ```\n\n### Advanced Queries\n\nPerform an advanced SQL-like query (make sure your query string contains the placeholder `[table]`):\n\n```python\nquery = \"SELECT * FROM [table] WHERE data LIKE '%sample%'\"\nmin_timestamp = datetime(2023, 1, 1)\nmax_timestamp = datetime(2023, 1, 31)\n\nresponse = client.advanced_query(\"weather_data\", query, min_timestamp, max_timestamp)\nprint(response)\n```\n\n### Managing Collections\n\n- **List All Collections**:\n  ```python\n  collections = client.get_collections()\n  for collection in collections:\n      print(f\"Collection: {collection.name}, Items: {collection.count}\")\n  ```\n\n- **Delete a Collection**:\n  ```python\n  response = client.delete_collection(\"weather_data\")\n  print(response)\n  ```\n\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue for any bugs or feature requests.\n\n## License\n\nAll rights reserved.\n",
    "bugtrack_url": null,
    "license": "All Rights Reserved  Copyright (c) 2024 Gaspard Merten  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": "Motion Lake Client, a client for the Motion Lake API (a Mobility Data Lake)",
    "version": "0.0.15",
    "project_urls": {
        "Homepage": "https://github.com/GaspardMerten/motion-lake-client"
    },
    "split_keywords": [
        "motion-lake",
        " mobility",
        " data",
        " api",
        " client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e044744ca6f3850e2cd7df42966a272e1776271121768cc36c65ca2481a04b36",
                "md5": "26456f56c3d56faa104b20caa52d212f",
                "sha256": "c4a4e40849216709e0fd14bacddb05d3dae1bbe8c5b62238ad8dfaaabb60f4b9"
            },
            "downloads": -1,
            "filename": "motion_lake_client-0.0.15-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "26456f56c3d56faa104b20caa52d212f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6842,
            "upload_time": "2024-05-01T16:52:20",
            "upload_time_iso_8601": "2024-05-01T16:52:20.585220Z",
            "url": "https://files.pythonhosted.org/packages/e0/44/744ca6f3850e2cd7df42966a272e1776271121768cc36c65ca2481a04b36/motion_lake_client-0.0.15-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eec36cd674596cdcd65b4ab394e1d4e807dca33807c1605f9747ce7c85506014",
                "md5": "40de80e2704789ad01ad01282ed97837",
                "sha256": "7c11601934bed203cc4ace2600c22fabd3942b60bc05473f34e47f16711c450b"
            },
            "downloads": -1,
            "filename": "motion_lake_client-0.0.15.tar.gz",
            "has_sig": false,
            "md5_digest": "40de80e2704789ad01ad01282ed97837",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8098,
            "upload_time": "2024-05-01T16:52:27",
            "upload_time_iso_8601": "2024-05-01T16:52:27.649558Z",
            "url": "https://files.pythonhosted.org/packages/ee/c3/6cd674596cdcd65b4ab394e1d4e807dca33807c1605f9747ce7c85506014/motion_lake_client-0.0.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-01 16:52:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GaspardMerten",
    "github_project": "motion-lake-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "certifi",
            "specs": [
                [
                    "==",
                    "2024.2.2"
                ]
            ]
        },
        {
            "name": "charset-normalizer",
            "specs": [
                [
                    "==",
                    "3.3.2"
                ]
            ]
        },
        {
            "name": "idna",
            "specs": [
                [
                    "==",
                    "3.6"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "2.2.1"
                ]
            ]
        }
    ],
    "lcname": "motion-lake-client"
}
        
Elapsed time: 0.27684s