Skip to main content

Nutricare data access package

Project description

nutricare-data-packages

Nutricare 的数据访问基础包,封装 MongoDB 仓储与本地存储抽象基类。

安装

pip install nutricare-data-packages

快速使用

from pathlib import Path
import os

from nutricare_data_packages import StorageBase


class ReportStorage(StorageBase):
    @property
    def storage_subdir(self) -> str:
        return "reports"

    def _write_impl(self, relative_path: str, data: bytes) -> Path:
        target = self.resolve_path(relative_path)
        target.parent.mkdir(parents=True, exist_ok=True)
        target.write_bytes(data)
        return target


os.environ["mongodb_url"] = "127.0.0.1:27017"
os.environ["NUTRICARE_TICKET_ID"] = "ticket-001"
os.environ["NUTRICARE_TASK_ID"] = "task-001"

storage = ReportStorage()
storage.write_metadata(
    relative_path=relative_path,
    size=len(content),
    md5="...",
    status="pending",
)
path = storage.write(relative_path, content)

说明:

  • MongoDB 连接串只从环境变量 mongodb_url 读取。
  • 允许传入 127.0.0.1:27017mongodb:127.0.0.1:27017 或完整 mongodb://...
  • 文件写入会按 relative_path + md5 做幂等校验,已存在且一致时直接返回。

本地构建与发布

python -m pip install --upgrade build twine
python -m build
python -m twine check dist/*
python -m 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

nutricare_data_packages-0.1.5.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

nutricare_data_packages-0.1.5-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file nutricare_data_packages-0.1.5.tar.gz.

File metadata

  • Download URL: nutricare_data_packages-0.1.5.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for nutricare_data_packages-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3caf7626c8f00d6ed0329d3d997214ac73568717b2bff92fb4d7885374209897
MD5 250f3677588908ce585d834a82235128
BLAKE2b-256 af1fb36981edc77eaf751ff48be9dd80a18fe4cdf894560a45c39940b399a744

See more details on using hashes here.

File details

Details for the file nutricare_data_packages-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for nutricare_data_packages-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b18c5f1b18afa7815bc06316165dc99c6a80262166c9e21e7633cc3767b38d08
MD5 df522fdb1d22394c2db913218c887fd3
BLAKE2b-256 f6af5803ae1a8b53476df08184cee0bd974b7ef4ccf3ce59ca8b7cde4b331c09

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