inanJeong
이난's 프로그래밍 지식 사이트
inanJeong
전체 방문자
오늘
어제
  • 분류 전체보기 (83)
    • 회고록 및 개발일기 (4)
    • Advanced (0)
    • Python (18)
      • 파이썬 기초 (0)
      • 파이썬스럽게 개발하기 (6)
      • Django (5)
      • 고성능 파이썬 (0)
      • matplotlib (3)
      • Error (4)
    • 기타 (61)
      • Shell Script (2)
      • 라즈베리파이 (5)
      • 티스토리 꾸미기 (2)
      • 알고리즘 (2)
      • 소프트웨어 개발론 (0)
      • JIRA(프로젝트 관리 도구) (1)
      • git (1)
      • Swagger (1)
      • docker (2)
      • web_server (2)
      • MySQL (2)
      • front_end (3)
      • javascripts(typescript + ES.. (5)
      • ServerSideApplication (1)
      • Data Engineering (5)
      • flutter (2)
      • JSP (10)
      • Spring boot (5)
      • React (3)
      • elasticSearch (1)
      • AWS (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

인기 글

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
inanJeong

이난's 프로그래밍 지식 사이트

[python] mimesis - 파이썬 mock 데이터
Python/파이썬스럽게 개발하기

[python] mimesis - 파이썬 mock 데이터

2022. 8. 18. 13:04

python

👋 들어가기전

  • python스럽게 개발 전반적인 지식을 다음 페이지에 모아두고 있습니다. 필요시 확인하세요~

2022.07.19 - [Python/파이썬스럽게 개발하기] - [python] 파이썬스럽게 개발하기 다수의 링크

 

[python] 파이썬스럽게 개발하기 다수의 링크

※ 링크가 없을 경우 아직 작성 전 입니다. 🌈. 링크 모음 파이썬 공홈 파이썬 공식 github pep8 🌟🌟파이썬 문서 모음(공식) 🌟🌟 어썸 파이썬 Effective-Python 🌟python cheatsheet(기본기 요약 핸드북)

inhwanjeong.tistory.com

 

 

 

🚨 급한사람!!  이거만 보세요

Mimesis: The Fake Data Generator
  • mimesis는 파이썬을 이용한 mock(fake, dummy) 데이터를 생성하는 모듈이다.
  • Mimesis supports Python 3.8 (also PyPy 3.8), 3.9, and 3.10.
  • 설치
pip install mimesis
  • 기본 사용법
    • class 형태로 사용: Person, Car, Location
    • Generic 형태로 사용: generic.person.username()
    • Field 형태로 사용: field('color')
    • Locale: 데이터 출력 언어 설정
      • e.g. Locale.KO: 한국어
from mimesis import Person
from mimesis.locales import Locale
from mimesis.enums import Gender

person = Person(Locale.KO)
person.full_name(gender=Gender.FEMALE)
# Out[111]: '유연 가'

person.full_name(gender=Gender.MALE)
# Out[112]: '동준 구'
  • 스키마 형태 사용법
from mimesis import Schema, Field
from mimesis.locales import Locale

field = Field(Locale.DE)

schema = Schema(
    schema=lambda: {
        "pk": field("increment"),
        "name": field("full_name"),
        "email": field("email", domains=["example.org"]),
    }
)


>>> {'pk': 1, 'name': 'Wenzel Feigenbaum', 'email': 'cambridge1883@example.org'}
...
{'pk': 100, 'name': 'Gerard Garber', 'email': 'travelers1947@example.org'}
  • csv, json, object로 변환
from mimesis.locales import Locale
from mimesis.schema import Field, Schema

_ = Field(locale=Locale.EN)
schema = Schema(schema=lambda: {
    "pk": _("increment"),
    "name": _("text.word"),
    "version": _("version"),
    "timestamp": _("timestamp", posix=False),
})
schema.to_csv(file_path='data.csv', iterations=1000)
schema.to_json(file_path='data.json', iterations=1000)
schema.to_pickle(file_path='data.obj', iterations=1000)

>>>
pk,uid,name,version,timestamp
1,save,6.8.6-alpha.3,2018-09-21T21:30:43Z
2,sponsors,6.9.6-rc.7,2015-03-02T06:18:44Z
3,after,4.5.6-rc.8,2022-03-31T02:56:15Z
4,queen,9.0.6-alpha.11,2008-07-22T05:56:59Z

 

1.Python Mimesis

  • Mimesis 모듈은 다양한 언어로 다양한 목적을 위한 데이터를 생성하는 데이터 생성기이다. 데이터베이스를 채우거나 json, csv, API 등 여러 곳에서 사용될 수 있다.
  • 특징
    • 사용이 간단함.
    • 다양한 국가의 언어의 데이터를 생성할 수 있음
    • 성능이 좋음
    • 다양한 종류의 데이터를 제공
    • 확장성이 좋다.
    • 의존성이 낮음: 파이썬 기본 라이브러리 외 추가 종속성이 존재하지 않음
    • 스키마 베이스의 데이터를 생성할 수 있음

 

2.Python Mimesis Locale 국가

  • 데이터를 생성할 때 해당언어로 데이터를 생성함.
cs Locale.CS Czech Česky
da Locale.DA Danish Dansk
de Locale.DE German Deutsch
de-at Locale.DE_AT Austrian german Deutsch
de-ch Locale.DE_CH Swiss german Deutsch
el Locale.EL Greek Ελληνικά
en Locale.EN English English
en-au Locale.EN_AU Australian English English
en-ca LocALE.EN_CA Canadian English English
en-gb Locale.EN_GB British English English
es Locale.ES Spanish Español
es-mx Locale.ES_MX Mexican Spanish Español
et Locale.ET Estonian Eesti
fa Locale.FA Farsi فارسی
fi Locale.FI Finnish Suomi
fr Locale.FR French Français
hu Locale.HU Hungarian Magyar
is Locale.IS Icelandic Íslenska
it Locale.IT Italian Italiano
ja Locale.JA Japanese 日本語
kk Locale.KK Kazakh Қазақша
ko Locale.KO Korean 한국어
nl Locale.NL Dutch Nederlands
nl-be Locale.NL_BE Belgium Dutch Nederlands
no Locale.NO Norwegian Norsk
pl Locale.PL Polish Polski
pt Locale.PT Portuguese Português
pt-br Locale.PT_BR Brazilian Portuguese Português Brasileiro
ru Locale.RU Russian Русский
sk Locale.SK Slovak Slovensky
sv Locale.SV Swedish Svenska
tr Locale.TR Turkish Türkçe
uk Locale.UK Ukrainian Українська
zh Locale.ZH Chinese 汉语

3. Python Mimesis Class(API) 

전체 API 링크

 

API — Mimesis 6.0.0 documentation

API This part of the documentation covers all the public interfaces of Mimesis. Random Implements various helpers which are used in the various data providers. This module contains custom Random() class where implemented a lot of methods which are not incl

mimesis.name

  • 주요 데이터 위 링크에서 검색
    • Address - address, latitude, longitude
    • Finance - company
    • Datetime
    • Food - dish, drink, fruit, spices, vegetable
    • Person - age, blood_type, email, first_name, full_name, gender, height, language, last_name, password,telephone, title, university, weight
    • Science - dna_sequence, rna_sequence
    • Text - alpabet, color, level, sentence
    • Develop - boolean, os, programming_language, software_license, version
    • File - extension, file_name, size
    • Hardware - cpu, graphics, phone_model, ram_size, resolution, ssd_or_hdd
    • Internet - emoji, http_method, hostname, ip_v4, uri, url
    • Numeric - increment

 

 

https://github.com/lk-geimfari/mimesis

 

GitHub - lk-geimfari/mimesis: Mimesis is a high-performance fake data generator for Python, which provides data for a variety of

Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages. - GitHub - lk-geimfari/mimesis: Mimesis is a high-performance...

github.com

https://mimesis.name/en/latest/getting_started.html

 

Getting Started — Mimesis 6.0.0 documentation

Data Providers Mimesis support over twenty different data providers available, which can produce data related to food, people, computer hardware, transportation, addresses, and more. See API for more info. Warning Data providers are heavy objects since eac

mimesis.name

https://mimesis.name/en/latest/api.html#person

 

API — Mimesis 6.0.0 documentation

API This part of the documentation covers all the public interfaces of Mimesis. Random Implements various helpers which are used in the various data providers. This module contains custom Random() class where implemented a lot of methods which are not incl

mimesis.name

 

from mimesis import Person
from mimesis.locales import Locale
from mimesis.enums import Gender
person = Person(Locale.EN)

person.full_name(gender=Gender.FEMALE)
# Output: 'Antonetta Garrison'

person.full_name(gender=Gender.MALE)
# Output: 'Jordon Hall​

'Python > 파이썬스럽게 개발하기' 카테고리의 다른 글

[python] haversine, 위도 경도를 이용하여 거리를 구하는 모듈  (0) 2022.07.26
[python] *args and **kwargs  (0) 2022.07.19
[python] 파이썬스럽게 개발하기 다수의 링크  (0) 2022.07.19
[python] itertools  (0) 2022.03.17
[Python3] 동시성과 병렬성  (0) 2021.04.16
    'Python/파이썬스럽게 개발하기' 카테고리의 다른 글
    • [python] haversine, 위도 경도를 이용하여 거리를 구하는 모듈
    • [python] *args and **kwargs
    • [python] 파이썬스럽게 개발하기 다수의 링크
    • [python] itertools
    inanJeong
    inanJeong
    저작권 문제시 이메일 발송 부탁드립니다.(해당 게시글 바로 내리겠습니다.) ghjklla007@naver.com

    티스토리툴바