Skip to main content

Transform objects to and from similar structural mappings.

Project description

remapper

GitHub Workflow Status PyPI - Downloads GitHub

Transform objects to and from similar structural mappings. Useful for translating between sources of truth and presentational models of data.

Supports Python 3.8+. No dependencies.

Installation

$ pdm add remapper
# or
$ python -m pip install --user remapper

Usage

A trivial example for remap is converting one dataclass into another without having to manually pass attributes:

from dataclasses import dataclass

from remapper import remap

@dataclass
class Source:
    a: int
    b: int
    c: int

@dataclass
class Destination:
    a: int
    b: int
    c: int


dest = remap(Source(a=1, b=2, c=3), Destination)
# >> Destination(a=1, b=2, c=3)

A more useful example would be a mapping an internal database model to an externally-facing dataclass:

from dataclasses import dataclass

from remapper import remap
from sqlalchemy.orm import DeclarativeBase, Mapped, MappedAsDataclass

class Base(DeclarativeBase, MappedAsDataclass):
    pass

class Source(Base):
    id: Mapped[int] = mapped_column(init=False, primary_key=True)

    a: Mapped[int]
    b: Mapped[int]
    c: Mapped[int]

@dataclass
class Destination:
    a: int
    b: int
    c: int

source = Source(a=1, b=2, c=3)
await session.commit(source)

dest = remap(source, Destination)
# >> Destination(a=1, b=2, c=3)

License

This software is licensed under the BSD 3-Clause Clear License.

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

remapper-1.0.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

remapper-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file remapper-1.0.0.tar.gz.

File metadata

  • Download URL: remapper-1.0.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.2 CPython/3.11.2 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for remapper-1.0.0.tar.gz
Algorithm Hash digest
SHA256 970b1be80bbfc3235230fb04837a3aff84cddc80d50e5580b625e8b7d68c7ace
MD5 b15607fd520d500273a4c6e35c880571
BLAKE2b-256 67ca78323356ec9e8f9b1cbfc3ecc387b17dede585da76a6d65d83cecb3d6681

See more details on using hashes here.

File details

Details for the file remapper-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: remapper-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.2 CPython/3.11.2 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for remapper-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24234fb3c5f45a91abb96ea5ec79626c0e4ac133f07bcb8e4a20bd114aafeadc
MD5 f10e03acada5a2921411243d536835d9
BLAKE2b-256 a38d0ca508de03fee18cae1e0b2fdf7d806c56e3eda7656159e4345b4537a55d

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