Skip to main content

A Python library providing null-safe attribute and key access through a simple chaining API

Project description

safepath

A Python library providing null-safe attribute and key access through a simple chaining API.

Installation

pip install safepath

Usage

from safepath import sp

# Basic usage
data = {"user": {"name": "John"}}
name = sp(data)["user"]["name"]()  # Returns "John"
missing = sp(data)["user"]["age"]()  # Returns None

# Object attribute access
class User:
    def __init__(self):
        self.name = "John"
        self.address = None

user = User()
name = sp(user).name()  # Returns "John"
city = sp(user).address.city()  # Returns None

# Chaining
data = {
    "users": [
        {"profile": {"address": {"city": "New York"}}}
    ]
}
city = sp(data)["users"][0]["profile"]["address"]["city"]()  # Returns "New York"
missing = sp(data)["users"][1]["profile"]["address"]["city"]()  # Returns None

Features

  • Null-safe attribute access
  • Null-safe dictionary/list access
  • Method chaining
  • Immutable wrapper objects
  • Type hints support
  • Zero dependencies

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

safepath-0.1.0a3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

safepath-0.1.0a3-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file safepath-0.1.0a3.tar.gz.

File metadata

  • Download URL: safepath-0.1.0a3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for safepath-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 f00828e11ef977761013f57725f2ca6157c2a3b23f19f1180eaef5af7ad1ea20
MD5 b9b2572a28600c756697044d6f0f408b
BLAKE2b-256 5dd00691b94954c1cdaa6ceec2e42a716b11cb7815291f20c7fddb6e7a5da7ad

See more details on using hashes here.

File details

Details for the file safepath-0.1.0a3-py3-none-any.whl.

File metadata

  • Download URL: safepath-0.1.0a3-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for safepath-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 e437f397bfef0091ca7c7e6e6195566f5dd7e56070ebf70c2523e2fe419c7c30
MD5 450b266e1150c7ee24428541ae189570
BLAKE2b-256 05facc756f7c7070215c103c39a4611b0164df1ca82c170cae22792d5bc9f083

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