Skip to main content

A Python package for loading petroleum datasets

Project description

perd

A Python package for loading reservoir datasets from API endpoints.

Installation

pip install perd

Quick Start

Option 1: Using Global API Key (Recommended)

First, set your API key globally:

# Set API key globally (works across all projects)
perd set-key "your_api_key_here"

# Or use interactive setup
perd interactive

Then use in your Python code:

import perd as pds

# Initialize without API key (uses global key)
pds.initialize()

# Load a random reservoir dataset
df_random = pds.reservoir.load_random()
print(f"Loaded dataset with shape: {df_random.shape}")

Option 2: Using API Key in Code

import perd as pds

# Initialize with your API key
pds.initialize('your_api_key_here')

# Load a random reservoir dataset
df_random = pds.reservoir.load_random()
print(f"Loaded dataset with shape: {df_random.shape}")

Workflows

The package includes Dockerized workflows for common operations:

Available Workflows

  1. Add Workflow - Adds two numbers together
  2. Subtract Workflow - Subtracts one number from another
  3. PINN Workflow - Trains a Physics-Informed Neural Network (Transformer-based)

Running Workflows in Python

You can run workflows directly in Python:

from perd.workflows import add, subtract, pinn

# Run simple workflows
print(add(5, 3))       # 8
print(subtract(10, 4)) # 6

# Run PINN training workflow
results = pinn(epochs=50)
print(f"Final Loss: {results['final_loss']}")

# Visualize the loss history dynamically
from perd import visual # Or use pds.visual if imported as pds
visual.line_plot(results, y='loss_history', title="PINN Training Loss")

Building Workflow Containers

# Build all workflow Docker images
./build_workflows.sh

# Or build individually
docker build -t perd-add-workflow -f perd/workflows/add/Dockerfile .
docker build -t perd-subtract-workflow -f perd/workflows/substract/Dockerfile .

Running Workflows

# Run add workflow
docker run --rm perd-add-workflow 5.2 3.8

# Run subtract workflow
docker run --rm perd-subtract-workflow 10.5 4.3

See perd/workflows/README.md for more details.

Command Line Interface

The package includes a CLI for managing API keys globally:

# Set API key globally
perd set-key "your_api_key_here"

# Check configuration status
perd status

# Get stored API key (masked)
perd get-key

# Remove API key
perd remove-key

# Interactive setup
perd interactive

# Clear all configuration
perd clear

# Show help
perd --help

Complete Usage Examples

import perd as pds

# Initialize (uses global key if available)
pds.initialize()

# Load a random reservoir dataset
df_random = pds.reservoir.load_random()
print(f"Loaded dataset with shape: {df_random.shape}")

# Load a specific dataset by ID
df_specific = pds.reservoir.load('your_dataset_id')

# Get information about available datasets
info = pds.get_dataset_info()

API Reference

initialize(api_key=None)

Initialize the perd module with API credentials.

Parameters:

  • api_key (str, optional): The API key for authentication. If not provided, uses globally stored key.

Note: If no API key is provided and none is stored globally, raises a ValueError with instructions to set a global key.

load_random()

Loads a random reservoir model from the API endpoint and returns as pandas DataFrame.

Returns:

  • pandas.DataFrame: A DataFrame containing the dataset

Configuration Management

The package stores configuration in ~/.perd/config.json by default:

{
  "api_key": "your_api_key_here"
}

Benefits of Global Configuration:

  • No API key in code: Keep sensitive keys out of your source code
  • Cross-project: Use the same API key across multiple projects
  • Secure: API keys are stored in user's home directory
  • Override: Can still provide API key in code to override global setting
  • Easy management: Use CLI commands to manage keys

Security Notes:

  • API keys are stored in plain text in your home directory
  • Only you can access the configuration file
  • Consider using environment variables for production deployments

Dependencies

  • requests>=2.25.1
  • pandas>=1.3.0

License

MIT

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Development

To set up the development environment:

git clone https://github.com/P-E-R-D/library-py.git
cd perd
pip install -e .

Building and Publishing

Automatic Deployment (Recommended)

This package uses GitHub Actions for automatic deployment to PyPI:

  1. Make your changes to the code
  2. Update version numbers in perd/__init__.py and pyproject.toml
  3. Create a git tag with the new version:
    git tag v0.2.0
    git push origin v0.2.0
    
  4. GitHub Actions automatically builds and uploads to PyPI!

See DEPLOYMENT.md for detailed setup instructions.

Manual Publishing

python -m build
twine upload dist/*

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

perd-0.0.1.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perd-0.0.1-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file perd-0.0.1.tar.gz.

File metadata

  • Download URL: perd-0.0.1.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for perd-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b51b8bd2e6a1a645f3d11aa543861906bfb22f1a1d82e01e7be290a8ea887791
MD5 e887a4da63521530e3e628538547959c
BLAKE2b-256 b734810bf93d67872dd1327bba77a3ffa445526ea69e1f53d01da673de7cba13

See more details on using hashes here.

File details

Details for the file perd-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: perd-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for perd-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa7d2a93b3513796822c987485d269747287c2db00b8d0bfc8c988ad006893c2
MD5 8c5a0c1e31bbbbe2a80bb62d9f7bf824
BLAKE2b-256 2e6797006963ad188d326fa621b174a64ec33b450ccb0dbf84eed379ab15e561

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page