🎓🕶️ A collection of utilities and demos from the Semantic Scholar Research Team 🕶️🎓
Project description
Shadow Scholar
Installation
To install from PyPI, simply run:
pip install shadow-scholar
Available Scripts
Each script is launched with shadow <entrypoint_name>
.
For a full list of all entry points, run shadow -l
.
Getting Access to AWS services
To run the scripts that use AWS services, you will need to have access to the following services:
The best way to do so is to obtain AWS credentials (access key and secret key) and set them as environment variables.
Writing your own script
To write your own script for Shadow Scholar, follow these steps:
Step 1: Choose where to add your code in Shadow Scholar. It can either be
in an existing module, such as shadow_scholar.collections.athena
, or in a
new module.
Step 2: Understand that the entry point for your script should be a single
function; think of this as the main
function.
Step 3: Write your main function. For each argument you expect a user might want to provide from command line, add a corresponding argument to the function. For example:
def my_script(
arg1: str,
arg2: int,
arg3: bool,
arg4: Optional[str] = None,
):
# Do something with the arguments
pass
Step 4: Add the cli from shadow_scholar.cli
to your script. This will
allow users to run your script from the command line. For example:
from shadow_scholar.cli import cli
from typing import Optional
@cli(
name="scripts_collection.my_script",
arguments=...,
requirements=...,
)
def my_script(
arg1: str,
arg2: int,
arg3: bool,
arg4: Optional[str] = None,
):
# Do something with the arguments
pass
The cli
decorator takes three arguments: the name of the script, a list
of arguments, and a list of requirements. The name of the script should be
the name a user would use to run the script from the command line. In the
example above, the user would run the script with shadow scripts_collection.my_script
.
Step 5: Add arguments to your script. Each argument should be an instance
of shadow_scholar.cli.Argument
. For example:
from typing import Optional
from shadow_scholar.cli import Argument, cli
@cli(
name="scripts_collection.my_script",
arguments=[
Argument(
name="arg1",
type=str,
help="This is the first argument",
),
Argument(
name="arg2",
type=int,
help="This is the second argument",
),
Argument(
name="arg3",
type=bool,
help="This is the third argument",
),
Argument(
name="arg4",
type=str,
help="This is the fourth argument",
default=None,
),
],
requirements=...,
)
def my_script(
arg1: str,
arg2: int,
arg3: bool,
arg4: Optional[str] = None,
):
# Do something with the arguments
pass
You should have as many Arguments as you have arguments to your main function.
Step 6: Add requirements to your script. Each requirement should be an
in the format used by requirements.txt
. When using optional requirements,
make sure to wrap them in a with safe_import()
statement at the top of your
script. For example:
from typing import Optional
from shadow_scholar.cli import Argument, cli, safe_import
with safe_import() as safe:
# this will not fail if pandas is not installed
import pandas as pd
@cli(
name="scripts_collection.my_script",
arguments=[
Argument(
name="arg1",
type=str,
help="This is the first argument",
),
Argument(
name="arg2",
type=int,
help="This is the second argument",
),
Argument(
name="arg3",
type=bool,
help="This is the third argument",
),
Argument(
name="arg4",
type=str,
help="This is the fourth argument",
default=None,
),
],
requirements=[
"pandas>=1.0.0",
],
)
def my_script(
arg1: str,
arg2: int,
arg3: bool,
arg4: Optional[str] = None,
):
# Do something with the arguments
pass
Step 7: Import the function in the __init__.py
file of the module. For
example, if you added your script to shadow_scholar/examples.py
, you would
add the following to shadow_scholar/__init__.py
:
from shadow_scholar.examples import my_script
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file shadow-scholar-0.4.0.tar.gz
.
File metadata
- Download URL: shadow-scholar-0.4.0.tar.gz
- Upload date:
- Size: 1.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91d40001c1ac6deec3bcf0ddd54b28d94961070a4468922fff26d20efd5709e9 |
|
MD5 | 32f91d6aebb0383ac09d19775af0e8b4 |
|
BLAKE2b-256 | 0723fdf2a585deac5c5ce54bbb6f417364f5db8d69b3f097f668e31ca0e28d20 |
File details
Details for the file shadow_scholar-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: shadow_scholar-0.4.0-py3-none-any.whl
- Upload date:
- Size: 1.4 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 591ce8cba2980a21c902b7522279d2fa4f0b9b65b523e2a6c670c9475e29f950 |
|
MD5 | 48eb9caf79700ae4df2aaec6e285e6e2 |
|
BLAKE2b-256 | ea0e28b50d30e5bd47a8060da17455b736d313eadfe03e3298751ae418aaf546 |