Metadata-Version: 2.1
Name: flask-api-key-decorator
Version: 0.1.3
Summary: Simple Flask decorator for requiring an API key
Author-email: "@lumpenspace" <lumpenspace@gmail.com>
License: Copyright 2023 @lumpenspace
        
        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.
        
Project-URL: homepage, https://github.com/yourusername/flask-api-key-decorator
Project-URL: repository, https://github.com/yourusername/flask-api-key-decorator
Project-URL: documentation, https://yourusername.github.io/flask-api-key-decorator
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: flask

# Flask API Key Decorator

A simple decorator for requiring an API key in order to access flask endpoints or methods.

It checks for an API key and adds the requirement to the swagger documentation.

## Installation

```bash
pip install flask-api-key-decorator
```

## Usage

Import the library

```
from require_api_key import require_api_key
```

Use it to decorate your Flask routes:

```python
@app.route('/')
@require_api_key
def home():
    return "Hello, World!"
```

By default, the decorator looks for the API key in the 'x-api-key' header. If you want to use a different header, you can specify it using the header_name parameter:

```python
@app.route('/')
@require_api_key(header_name='custom-header')
def home():
    return "Hello, World!"
```

## Setting the API key

The API key can be set in two ways:

1. As an environment variable named `API_KEY`
2. As an argument to the decorator

```python
@app.route('/')
@require_api_key(key='your-api-key')
def home():
    return "Hello, World!"
```

To set multiple API keys, separate them with a comma.

```bash
export API_KEY=your-api-key-1,your-api-key-2
```

## License

MIT (see [LICENSE.md](LICENSE.md)
