Skip to content

Commit 3496c69

Browse files
committed
Document optional python-dotenv setup and add .env template
1 parent 7344eb8 commit 3496c69

File tree

6 files changed

+110
-113
lines changed

6 files changed

+110
-113
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# REDCap API credentials
2+
REDCAP_API_URL=https://redcap.example.edu/api/
3+
REDCAP_API_KEY=replace-with-your-api-token

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ To install the bleeding edge version from the github repo, use the following
3131
$ pip install -e git+https://github.com/redcap-tools/PyCap.git#egg=PyCap
3232
```
3333

34+
## Quickstart
35+
36+
1. Copy `.env.example` to `.env` and update the values with your REDCap endpoint and API token.
37+
2. Install [`python-dotenv`](https://pypi.org/project/python-dotenv/) with `pip install python-dotenv` (or add it to your Poetry environment).
38+
39+
Then load your credentials and connect:
40+
41+
```python
42+
from dotenv import load_dotenv
43+
import os
44+
from redcap import Project
45+
46+
load_dotenv() # reads .env from the project root
47+
48+
api_url = os.environ["REDCAP_API_URL"]
49+
api_key = os.environ["REDCAP_API_KEY"]
50+
project = Project(api_url, api_key)
51+
```
52+
3453
## Documentation
3554

3655
Canonical documentation and usage examples can be found [here](https://redcap-tools.github.io/PyCap/).

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ If you want to load REDCap data into [`pandas`](https://pandas.pydata.org/) data
1616
$ pip install PyCap[all]
1717
```
1818

19-
For secure credential management, create a `.env` file in your project root with your REDCap credentials:
19+
For secure credential management, install [`python-dotenv`](https://pypi.org/project/python-dotenv/) (`pip install python-dotenv`) and create a `.env` file in your project root with your REDCap credentials:
2020

2121
```dotenv
2222
REDCAP_API_URL=https://redcap.example.edu/api/

docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PyCap makes it very simple to interact with the data stored in your REDCap projects
44

5-
> First, install python-dotenv (`poetry add python-dotenv`) and create a `.env` file in your project root with your REDCap credentials:
5+
> First, install python-dotenv (`pip install python-dotenv` or `poetry add python-dotenv`) and create a `.env` file in your project root with your REDCap credentials:
66
77
```dotenv
88
REDCAP_API_URL=https://redcap.example.edu/api/

0 commit comments

Comments
 (0)