semvec/pypi-packages huggingface dataset:
colorsplash-common 0.3.1
A common set of classes for the ColorSplash project python components
License: MIT
Requires Python: >=3.8,<4.0

# colorsplash-common

## Description

colorsplash-common (CSC) is a component of the overarching ColorSplash web application that can be found at https://thurau.io/colorsplash/. ColorSplash allows users to browse royalty free images that have colors within a certain Euclidean distance of a provided HEX code. CSC is a python library hosted on PyPi to allow common features to be included as dependencies within the other python componenets.

You can see other components of this project in the following Github repos
- [ColorSplashPhotoRetrieval](https://github.com/DanielThurau/ColorSplashPhotoRetrieval)
- [ColorSplashPhotoProcessor](https://github.com/DanielThurau/ColorSplashPhotoProcessor)
- [ColorSplashColorDetector](https://github.com/DanielThurau/ColorSplashColorDetector)
- [thurau.io](https://github.com/DanielThurau/thurau.io)

## Motivation

A friend was facing issues when trying to create social media posts for an ecommerce company we recently launched. She had developed a branding guide and had chosen what colors she wanted to include in the website, logos, and eventual marketing material. But when it was time to make marketing posts, trying to apply that style guide was difficult. For all the tools on the internet she used, none were able to query royalty free images that were close to the HEX color codes she had selected. This project was born to remedy this issue.

I wanted to provide a clean minimal interface on a website that would have a form for a HEX code, and query a REST API that would return royalty free images that had a subset of colors within close to the original HEX code.

## Tech Used

CSC is a very simple python library that tightly couples integration with the various DynamoDB tables in the project. It uses boto3 as the client library.

## Installation

### Cloning The Project

You can either fork the repo or clone it directly with

```shell
$ git clone https://github.com/DanielThurau/colorsplash-common.git
$ cd colorsplash-common
```

### Developing

This project uses [poetry](https://python-poetry.org/) to build, test, and publish.

To install dependencies run

```shell
$ poetry install
```

To run the unit tests run

```shell
$ poetry run pytest
```


## Usage

CSC is hosted on PyPi so you can use any tool that integrates with PyPi to bring it in as a dependency. The easiest way is with pip. For example

```shell
$ pip install colorsplash-common
```

// TODO link a Github gist showing the use of the library

## Contribute

If you'd like to contribute, fork the project and submit a Pull Request.

## License

See LICENSE.md

> MIT License
>
> Copyright (c) 2021 Daniel Thurau
local-responder 0.2.0
A asynchronous temporary web server to repond to requests
License: MIT
Requires Python: >=3.7,<4.0

# Local Responder

Local Responder is a helper context manager that creates a web server with just
one view that has only one purpose, to return simple predefined data.

This is created just for the purpose of using in tests, to mock out an API in a
very simple manner. It's mostly useful for a blackbox like test where you are
mocking out an external API while making requests to the "blackbox" api.

## Usage

You can import the `respond` function and use it as an asynchronous context manager

```python
import asyncio
import aiohttp
from local_responder import respond


async def func() -> None:
    async with aiohttp.ClientSession() as session:
        async with respond(
            json={"status": "OK"},
            path="/health",
            method="get",
            status_code=200,
        ) as api:
            response = await session.get("http://localhost:5000/health", params={"foo": "bar"})

            data = await response.json()

            assert data == {"status": "OK"}
            assert response.status == 200
            assert len(api.calls) == 1
            assert api.calls[0].query == {"foo": "bar"}

        async with respond(
            json={"status": "Error"},
            path="/health",
            method="get",
            status_code=500,
        ):
            response = await session.get("http://localhost:5000/health")

            data = await response.json()

            assert data == {"status": "Error"}
            assert response.status == 500


if __name__ == "__main__":
    asyncio.run(func())
```

The context manager will raise an error if a request is made to an undefined
path or using an unsupported method.

You need to provide one of `json`, `text` or `body` for the view to return, the
other arguments are all optional, defaulting to creating a `GET` view with a
status code 200 and listen on port 5000.

## Request tracking

Each request made to the view while it is alive is tracked. The tracker simply
tracks the request method, path, headers, query and json payload if there is
one. Each tracked request is stored in a `RequestTracker` instance that is
yielded from the context manager. Example of call verification is in the
example above.