Skip to content

Commit

Permalink
Merge pull request #85 from impresso/feature_dotenv
Browse files Browse the repository at this point in the history
Add dotenv functionality
  • Loading branch information
piconti authored Mar 14, 2024
2 parents 94d2a0a + 9d25922 commit 91e576a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ With `pip`:
pip install impresso-commons
```

## Notes
The library supports configuration of s3 credentials via project-specific local .env files.

## License

The second project 'impresso - Media Monitoring of the Past II. Beyond Borders: Connecting Historical Newspapers and Radio' is funded by the Swiss National Science Foundation (SNSF) under grant number [CRSII5_213585](https://data.snf.ch/grants/grant/213585) and the Luxembourg National Research Fund under grant No. 17498891.
Expand Down
8 changes: 8 additions & 0 deletions impresso_commons/utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import bz2
from smart_open.s3 import iter_bucket
from smart_open import open as s_open
from dotenv import load_dotenv

from impresso_commons.utils import _get_cores

Expand All @@ -20,6 +21,8 @@


def get_storage_options():
# load environment variables from local .env files
load_dotenv()
return {
"client_kwargs": {"endpoint_url": "https://os.zhdk.cloud.switch.ch"},
"key": os.environ["SE_ACCESS_KEY"],
Expand All @@ -42,6 +45,9 @@ def get_storage_options():


def get_s3_client(host_url="https://os.zhdk.cloud.switch.ch/"):

# load environment variables from local .env files
load_dotenv()
if host_url is None:
try:
host_url = os.environ["SE_HOST_URL"]
Expand Down Expand Up @@ -77,6 +83,8 @@ def get_s3_resource(host_url="https://os.zhdk.cloud.switch.ch/"):
:rtype: `boto3.resources.factory.s3.ServiceResource`
"""

# load environment variables from local .env files
load_dotenv()
if host_url is None:
try:
host_url = os.environ["SE_HOST_URL"]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ dependencies = [
"numpy",
"smart_open",
"jsonlines",
"s3fs"
"s3fs",
"python-dotenv"
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ pyrsistent>=0.19.3
pytest>=7.4.2
python-box>=7.1.1
python-dateutil>=2.8.2
python-dotenv>=1.0.1
python-json-logger>=2.0.7
python-jsonpath>=0.7.1
python-jsonschema-objects>=0.5.0
Expand Down

0 comments on commit 91e576a

Please sign in to comment.