Code Monkey home page Code Monkey logo

type_mappers's Introduction

This project is incomplete and undergoing major change. It is currently unstable and thus not meant for production use.

Type Mapper

A utility to map primitive types (int, str, bool, etc) to the equivalent in various python libraries.

What?

It's really simple easy: using a 'string' representation, this utility maps commonly named types into their actual programmatic equivalent. An example will help:

given 'str' and 'boolean', we know intuitively that these will always map to str and bool in python, respectively.

But that's just the simple stuff. There are many more types that don't have an exact equivalent in python (double, long, etc..., which map to float in this case), so we use the most obvious approximation. These are very predictable, so you'll get what you expect.

When it comes to building classes or other functionality dynamically, there are often times when primitive types are involved.

This is especially true for code generation.

Many scenarios where some collection of types need to map to another similar collection, but more specific: an int to a sqlalchemy field, wtform field, or something else entirely. This is such a fundamental thing to do that it seems that a library ought to exist for many of these scenarios.

Goals

  • Be dead simple to use
  • Extremely lighweight
  • Have a very comprehensive set of unique mappings
  • Have a very comprehensive set of synonymous mappings (str, string, text, word, etc... all really mean the same thing.)

Contexts

Currently the following exist:

  • Vanilla (native python)
  • SqlAlchemy
  • WTForms
  • Factory Boy

Want to see new ones? File an issue!

Built on these simple rules:

  • The mapping key is always a string representation so it can be stored in a dictionary and not be confused with another type.
  • All mappings TO a type must be callable. You will always get back a callable type.

Future ideas for types/support

HTML5 types

  • color
  • email

GIS/Geospatial

  • coordinates
  • geojson

More specific datastructure types

  • 2-3-n-tuples (enforced as a callable wrapper around tuple)
  • OrderedDict
  • NamedTuple
  • Class

Tests

Tests mainly ensure that there is parity across each context. To run, assuming you are in a virtualenv and have run pip install -e ., then run pytest tests.

type_mappers's People

Contributors

christabor avatar

Stargazers

 avatar

Watchers

 avatar  avatar

type_mappers's Issues

Need a way to manage deps per mapping

Many users will likely not want to install every single dependency if they want only one specific mapper. Not sure if there is an easy solution regarding automatic dependency installation via setup tools.

swagger_wtforms and type_mappers

This project seems to be a replacement for swagger_wtforms, but it also seems that both projects stalled a couple of years ago. That happens.

I'm currently in the situation that I need exactly what these projects offer (wtform classes based on swagger specs) and I was wondering if there is a more obvious way to do this today, that I'm missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.