WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# REDCap API credentials
REDCAP_API_URL=https://redcap.example.edu/api/
REDCAP_API_KEY=replace-with-your-api-token
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ To install the bleeding edge version from the github repo, use the following
$ pip install -e git+https://github.com/redcap-tools/PyCap.git#egg=PyCap
```

## Quickstart

1. Copy `.env.example` to `.env` and update the values with your REDCap endpoint and API token.
2. Install [`python-dotenv`](https://pypi.org/project/python-dotenv/) with `pip install python-dotenv` (or add it to your Poetry environment).

Then load your credentials and connect:

```python
from dotenv import load_dotenv
import os
from redcap import Project

load_dotenv() # reads .env from the project root

api_url = os.environ["REDCAP_API_URL"]
api_key = os.environ["REDCAP_API_KEY"]
project = Project(api_url, api_key)
```

## Documentation

Canonical documentation and usage examples can be found [here](https://redcap-tools.github.io/PyCap/).
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ If you want to load REDCap data into [`pandas`](https://pandas.pydata.org/) data
$ pip install PyCap[all]
```

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:

```dotenv
REDCAP_API_URL=https://redcap.example.edu/api/
REDCAP_API_KEY=YourSuperSecretAPIKeyHere
```

To install the bleeding edge version from the github repo, use the following

```sh
Expand Down
17 changes: 15 additions & 2 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@

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

> 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:

```dotenv
REDCAP_API_URL=https://redcap.example.edu/api/
REDCAP_API_KEY=SomeSuperSecretAPIKeyThatNobodyElseShouldHave
```

Then update your code to load the values from the environment:

```python
from dotenv import load_dotenv
import os
from redcap import Project

api_url = 'https://redcap.example.edu/api/'
api_key = 'SomeSuperSecretAPIKeyThatNobodyElseShouldHave'
load_dotenv() # Load variables from .env file

api_url = os.getenv('REDCAP_API_URL')
api_key = os.getenv('REDCAP_API_KEY')
project = Project(api_url, api_key)
```

Expand Down
Loading