websnap
Copies files retrieved from an API to an S3 bucket or a local machine.
Installation
pip install websnap
Quickstart
Websnap can be used as a function or as a CLI.
Click here to view a websnap overview diagram.
Function
from websnap import websnap
# Execute websnap using default arguments
websnap()
# Execute websnap passing arguments
websnap(file_logs=True, s3_uploader=True, endpoint_url="https://examplecloud.com", backup_s3_count=7, early_exit=True)
CLI
To access CLI documentation in terminal execute:
websnap-cli --help
Function Parameters / CLI Options
Click to unfold
Function Parameters
| Parameter | Type | Default |
|---|---|---|
config |
str |
"config.ini" |
log_level |
str |
"INFO" |
file_logs |
bool |
False |
s3_uploader |
bool |
False |
profile_name |
str | None |
None |
endpoint_url |
str | None |
None |
backup_s3_count |
int | None |
None |
timeout |
int |
32 |
early_exit |
bool |
False |
section_config |
str | None |
None |
CLI Options
| Option | Default |
|---|---|
--config |
config.ini |
--log-level |
INFO |
--file-logs |
False |
--s3-uploader |
False |
--profile-name |
None |
--endpoint-url |
None |
--backup-s3-count |
None |
--timeout |
32 |
--early-exit |
False |
--section-config |
None |
Description
| Function parameter / CLI option |
Description |
|---|---|
config (str) |
|
log_level (str) |
|
file_logs (bool) |
|
s3_uploader (bool) |
|
profile_name (str | None) |
|
endpoint_url (str | None) |
|
backup_s3_count (int | None) |
|
timeout (int) |
|
early_exit (bool) |
|
section_config (str | None) |
|
Usage: S3 Bucket
Click to unfold
Copy files retrieved from an API to an S3 bucket.
Utilizes the AWS SDK for Python (Boto3) to add and backup API files as objects in an S3 bucket.
Credentials
Use a shared credentials file to export records to an S3 bucket.
Click here
to learn about Boto3 shared credentials file, expected default location of file (~/.aws/credentials), supported configuration variables, and profiles.
Note: Be aware that environment variables will take precedence over a shared credentials file! Click here to learn more about the order that Boto3 searches for credentials.
The CLI will use the [default] settings in the shared credentials file unless the option --profile-name is used.
Example ~/.aws/credentials file:
[default]
aws_access_key_id=food
aws_secret_access_key=bard
If using the CLI option --profile-name option then a specific configuration profile can be used in the ~/.aws/credentials file:
[default]
aws_access_key_id=food
aws_secret_access_key=bard
[dev]
aws_access_key_id=snack
aws_secret_access_key=singer
Function Examples
# The s3_uploader argument must be passed as True to copy files as objects to an S3 bucket
# If s3_uploader is True then the endpoint_url argument must also be passed
# Copies objects to an S3 bucket
websnap(s3_uploader=True, endpoint_url="https://examplecloud.com")
# Copies objects to an S3 bucket and at maximum 4 backup objects are allowed for each
# config section
websnap(s3_uploader=True, endpoint_url="https://examplecloud.com", backup_s3_count=4)
CLI Examples
Required Options
- The following CLI options must be used to enable websnap to upload files as objects in an S3 bucket:
--s3-uploader--endpoint-urlmust be assigned to the complete URL to use for the constructed S3 client
Basic Usage
- Copies objects to an S3 bucket using default argument values
websnap-cli --s3-uploader --endpoint-url "https://examplecloud.com"
Advanced Usage
- Copies objects to an S3 bucket
- Specify
devas the profile to use in the~/.aws/credentialsfile - At maximum 4 backup objects are allowed for each config section
- Enable logging to a file
websnap-cli --s3-uploader --profile-name dev --endpoint-url "https://examplecloud.com" --backup-s3-count 4 --file-logs
Configuration
- A valid
.inior.jsonconfiguration file is required. - Websnap expects the config to be
config.iniin the same directory as websnap package is being executed from.- However, this can be changed using the
configfunction argument (or CLI--configoption).
- However, this can be changed using the
S3 Configuration Example Files
| Format | Example Configuration File |
|---|---|
.ini |
src/websnap/config_templates/s3_config_template.ini |
.json |
src/websnap/config_templates/s3_config_template.json |
S3 Configuration Sections (one per API URL endpoint)
- Each file retrieved from an API requires its own configuration section!
- The section name be anything, it is suggested to have a name that relates to the copied file.
Example S3 config section configuration with key prefix:
[resource]
url=https://www.example.com/api/resource
bucket=exampledata
key=subdirectory_resource/resource.xml
Example S3 config section configuration without key prefix:
[project]
url=https://www.example.com/api/project
bucket=exampledata
key=project.json
| Key | Value Description |
|---|---|
url |
API URL endpoint that file will be retrieved from |
bucket |
Bucket that file (as an object) will be written in |
key |
Object key name with extension, can optionally include prefix |
Usage: Local Machine
Click to unfold
Copy files retrieved from an API to a local machine.
Examples
Function
# Write files retrieved from an API to local machine using default argument values
websnap()
# Write files retrieved from an API locally and file logs are enabled
websnap(file_logs=True)
CLI
-
Write copied files to local machine using default argument values:
websnap-cli
-
Write copied files locally and file logs are enabled:
websnap-cli --file-logs
Configuration
- A valid
.inior.jsonconfiguration file is required for both function and CLI usage. - Websnap expects the config to be
config.iniin the same directory as websnap package is being executed from.- However, this can be changed using the
configfunction argument (or CLI--configoption).
- However, this can be changed using the
- Each file that will be retrieved from an API requires its own section.
- If the optional
directorykey/value pair is omitted then the file will be written in the directory that the program is executed from.
Configuration Example Files
| Format | Example Configuration File |
|---|---|
.ini |
src/websnap/config_templates/config_template.ini |
.json |
src/websnap/config_templates/config_template.json |
Sections (one per API URL endpoint)
Example local machine configuration section:
[project]
url=https://www.example.com/api/project
file_name=project.json
directory=projectdata
| Key | Value Description |
|---|---|
url |
API URL endpoint that file will be retrieved from |
file_name |
File name with extension |
directory (optional) |
Local directory name that file will be written in |
Logs
Click to unfold
Websnap supports optional rotating file logs.
- The following CLI option must be used to enable websnap to support rotating file logs:
--file-logs- In function usage the following argument must be passed to support rotating file
logs:
file_logs=True
- In function usage the following argument must be passed to support rotating file
logs:
- Log is called by default
websnap.log - If log keys are not specified in the configuration
[DEFAULT]section then default values in the table below will be used. log_whenexpects a value used by logging module TimedRotatingFileHandler.- Click here for more information about how to use TimedRotatingFileHandler.
- The default values result in the file logs being rotated once every day and no removal of backup log files.
Configuration
Example log configuration:
[DEFAULT]
log_when=midnight
log_interval=1
log_backup_count=7
[DEFAULT] Section
| Key | Default | Value Description |
|---|---|---|
log_when |
D |
Specifies type of interval |
log_interval |
1 |
Duration of interval (must be positive integer) |
log_backup_count |
0 |
If nonzero then at most <log_backup_count> files will be kept,oldest log file is deleted (must be non-negative integer) |
Minimum Download Size
Click to unfold
Websnap supports optionally specifying the minimum download size (in kilobytes) a file must be to copy it from the configured API URL endpoint.
- By default the minimum default minimum size is 0 kb.
- Unless specified in the configuration this means that a file of any size can be downloaded by websnap.
- Configured minimum download size must be a non-negative integer.
- If the content from the API URL endpoint is less than the configured size:
- An error will be logged and the program continues to the next config section.
- If the CLI option
--early-exit(or function argumentearly_exit=True) is enabled then the program will terminate early.
Configuration
Example minimum download size configuration:
[DEFAULT]
min_size_kb=1
[DEFAULT] Section
| Key | Default | Value Description |
|---|---|---|
min_size_kb |
0 |
Minimum download size in kilobytes (must be non-negative integer) |
Author
Purpose
This project was developed to facilitate EnviDat resiliency and support continuous operation during server maintenance.
EnviDat is the environmental data portal of the Swiss Federal Institute for Forest, Snow and Landscape Research WSL.
License
Metadata
Release files for websnap 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| websnap-4.0.0.tar.gz | 28.3 kB | Without provenance | Details for websnap-4.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| websnap-4.0.0-py3-none-any.whl | Python 3 | none | any | Details for websnap-4.0.0-py3-none-any.whl |
Total release size: 49.5 kB
Release files / websnap-4.0.0.tar.gz
| Download URL | websnap-4.0.0.tar.gz |
|---|---|
| Size | 28.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b5808e12ab2a766c7bf74b2ff9e177d2906a10dc0866251681a6b88fb58d8f6e
|
|
BLAKE2b-256 checksum How to use checksums |
ab8cd2f88746c9de64ebcf1ca2c4657fee38bd73f97868845882deaa9f3a3fdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.8 CPython/3.14.4 Linux/6.8.0-110-generic
|
Release files / websnap-4.0.0-py3-none-any.whl
| Download URL | websnap-4.0.0-py3-none-any.whl |
|---|---|
| Size | 21.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1fff8dd13ae92479fbbfa7d99f105135aaeaa0d4b45014398460e136dbff56dd
|
|
BLAKE2b-256 checksum How to use checksums |
80e20b5de4148fe50bdbd9aed7d5be6ef9302d25d3c993700074e2dc2deaddb0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.8 CPython/3.14.4 Linux/6.8.0-110-generic
|
Security for websnap 4.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.