Accessing environment variables for lazy people.
Project description
# Environmentalist - use API secrets easily
Environmentalist helps API users to retrive API secrets from the environment
easily.
## The problem
I'm tired of rewriting the following code over and over again to get my app key
from the environment variables.
```python
import os
from requests_oauthlib import OAuth1Session
api = OAuth1Session(client_key=os.environ.get('TWITTER_CLIENT_KEY'),
client_secret=os.environ.get('TWITTER_CLIENT_SECRET'),
resource_owner_token=os.environ.get('TWITTER_RESOURCE_OWNER_TOKEN'),
resource_owner_secret=os.environ.get('TWITTER_RESOURCE_OWNER_SECRET'))
```
## Project dependencies
1. N/A
## Usage
Use an instance to easily create your API instance, for example:
```bash
# Create environment variables with the same prefix
set TWITTER_CLIENT_KEY=xxx
set TWITTER_CLIENT_SECRET=xxx
set TWITTER_RESOURCE_OWNER_TOKEN=xxx
set TWITTER_RESOURCE_OWNER_SECRET=xxx
```
```python
from environmentalist import E
api = OAuth1Session(**E(prefix='TWITTER'))
api.get('https://api.twitter.com/1.1/statuses/home_timeline.json')
```
When you create the `E` instance, it filter and strips the prefix out of the
environment variables.
Or you can dump all the environment variables for no reason:
```python
print(E())
# {'HOME': '...', ...}
```
Environmentalist helps API users to retrive API secrets from the environment
easily.
## The problem
I'm tired of rewriting the following code over and over again to get my app key
from the environment variables.
```python
import os
from requests_oauthlib import OAuth1Session
api = OAuth1Session(client_key=os.environ.get('TWITTER_CLIENT_KEY'),
client_secret=os.environ.get('TWITTER_CLIENT_SECRET'),
resource_owner_token=os.environ.get('TWITTER_RESOURCE_OWNER_TOKEN'),
resource_owner_secret=os.environ.get('TWITTER_RESOURCE_OWNER_SECRET'))
```
## Project dependencies
1. N/A
## Usage
Use an instance to easily create your API instance, for example:
```bash
# Create environment variables with the same prefix
set TWITTER_CLIENT_KEY=xxx
set TWITTER_CLIENT_SECRET=xxx
set TWITTER_RESOURCE_OWNER_TOKEN=xxx
set TWITTER_RESOURCE_OWNER_SECRET=xxx
```
```python
from environmentalist import E
api = OAuth1Session(**E(prefix='TWITTER'))
api.get('https://api.twitter.com/1.1/statuses/home_timeline.json')
```
When you create the `E` instance, it filter and strips the prefix out of the
environment variables.
Or you can dump all the environment variables for no reason:
```python
print(E())
# {'HOME': '...', ...}
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file environmentalist-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: environmentalist-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b30228b77d69e5bb82865a9c09019f032c0e9a574db7ddbdddbdb2cd440e5f29 |
|
MD5 | e8afff2515bc47f27f8970068d616c55 |
|
BLAKE2b-256 | 7c4bf72e26182463b28ba3417317b9bf46d09b9a9f8b6137286354669ce3be2f |