All Projects → Yardanico → Nimpylib

Yardanico / Nimpylib

Licence: mit
Some python standard library functions ported to Nim

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects
nim
578 projects
python2
120 projects

Projects that are alternatives of or similar to Nimpylib

Ngx Ui
🚀 Style and Component Library for Angular
Stars: ✭ 534 (+506.82%)
Mutual labels:  hacktoberfest, library
Whatpulse
WhatPulse reverse engineered
Stars: ✭ 30 (-65.91%)
Mutual labels:  hacktoberfest, library
Leku
🌍 Map location picker component for Android. Based on Google Maps. An alternative to Google Place Picker.
Stars: ✭ 612 (+595.45%)
Mutual labels:  hacktoberfest, library
Virtualenv
Virtual Python Environment builder
Stars: ✭ 4,017 (+4464.77%)
Mutual labels:  hacktoberfest, library
Sanity Typed Queries
A typed, zero-dependency schema generator and query builder for Sanity.
Stars: ✭ 54 (-38.64%)
Mutual labels:  hacktoberfest, library
Ferret
Declarative web scraping
Stars: ✭ 4,837 (+5396.59%)
Mutual labels:  hacktoberfest, library
Xtoolkit.whitelabel
Modular MVVM framework for fast creating powerful cross-platform applications with Xamarin.
Stars: ✭ 22 (-75%)
Mutual labels:  hacktoberfest, library
Gerador Validador Cpf
Biblioteca JS open-source para gerar e validar CPF.
Stars: ✭ 312 (+254.55%)
Mutual labels:  hacktoberfest, library
Lingua Franca
Mycroft's multilingual text parsing and formatting library
Stars: ✭ 51 (-42.05%)
Mutual labels:  hacktoberfest, library
Siler
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
Stars: ✭ 1,056 (+1100%)
Mutual labels:  hacktoberfest, library
Anglesharp
👼 The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.
Stars: ✭ 4,018 (+4465.91%)
Mutual labels:  hacktoberfest, library
Loadingshimmer
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.
Stars: ✭ 1,180 (+1240.91%)
Mutual labels:  hacktoberfest, library
Kiimagepager
The KIImagePager is inspired by foursquare's ImageSlideshow, the user may scroll through images loaded from the Web
Stars: ✭ 324 (+268.18%)
Mutual labels:  hacktoberfest, library
Telethon
Pure Python 3 MTProto API Telegram client library, for bots too!
Stars: ✭ 5,805 (+6496.59%)
Mutual labels:  hacktoberfest, library
Grabana
User-friendly Go library for building Grafana dashboards
Stars: ✭ 313 (+255.68%)
Mutual labels:  hacktoberfest, library
Lambdacd
a library to define a continuous delivery pipeline in code
Stars: ✭ 655 (+644.32%)
Mutual labels:  hacktoberfest, library
Cosmos
Hacktoberfest 2021 | World's largest Contributor driven code dataset | Algorithms that run our universe | Your personal library of every algorithm and data structure code that you will ever encounter |
Stars: ✭ 12,936 (+14600%)
Mutual labels:  hacktoberfest, library
Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (+190.91%)
Mutual labels:  hacktoberfest, library
Mod Pbxproj
A python module to manipulate XCode projects
Stars: ✭ 959 (+989.77%)
Mutual labels:  hacktoberfest, library
Whisper
Whisper is a file-based time-series database format for Graphite.
Stars: ✭ 1,121 (+1173.86%)
Mutual labels:  hacktoberfest, library

NimPylib

Build status Issues PRs Commits

Nimpylib is a collection of Python-like operators and functions (syntax sugar). It can help you to translate your Python program to Nim.

Usage

import pylib

print 42  # print can be used with and without parenthesis too, like Python2.
print( f"{9.0} Hello {42} World {1 + 2}" ) # Python-like string interpolation
let python_like_range = xrange(0, -10, -2) # range() is named xrange() like Python2
print(list(python_like_range)) # @[0, -2, -4, -6, -8]

for i in xrange(10):
  # 0 1 2 3 4 5 6 7 8 9
  print(i, endl=" ")
print("done!")

# Python-like variable unpacking
let data = list(xrange(3, 15, 2))
data.unpack(first, second, *rest, last)
assert (first + second + last) == (3 + 5 + 13)
assert rest == @[7, 9, 11]

if (a := 6) > 5:
  assert a == 6

if (b := 42.0) > 5.0:
  assert b == 42.0

if (c := "hello") == "hello":
  assert c == "hello"

print(capwords("hello world capitalized")) # "Hello World Capitalized"
print("a".center(9)) # "         a         "

print("" or "b") # "b"
print("a" or "b") # "a"

print(not "") # true

print("Hello,", input("What is your name? "), endl="\n~\n")

pass # do nothing
pass str("This is a string.") # discard the string

let integer_bytes = 2_313_354_324
var bite, kilo, mega, giga, tera, peta, exa, zetta, yotta: int
(kilo, bite) = divmod(integer_bytes, 1_024)
(mega, kilo) = divmod(kilo, 1_024)
(giga, mega) = divmod(mega, 1_024)
(tera, giga) = divmod(giga, 1_024)
(peta, tera) = divmod(tera, 1_024)
(exa, peta)  = divmod(peta, 1_024)
(zetta, exa) = divmod(exa,  1_024)
(yotta, zetta) = divmod(zetta, 1_024)

let arg = "hello"
let anon = lambda: arg + " world"
assert anon() == "hello world"

print(json_loads("""{"key": "value"}""")) # {"key":"value"}

print(sys.platform) # "linux"

print(platform.processor) # "amd64"

var truty: bool
truty = all([True, True, False])
print(truty) # false

truty = any([True, True, False])
print(truty) # true

from std/os import sleep

timeit(100):  # Python-like timeit.timeit("code_to_benchmark", number=int)
  sleep(9)    # Repeats this code 100 times. Output is very informative.

# 2020-06-17T21:59:09+03:00 TimeIt: 100 Repetitions on 927 milliseconds, 704 microseconds, and 816 nanoseconds, CPU Time 0.0007382400000000003.

# Support for Python-like with statements
# All objects are closed at the end of the with statement
with open("some_file.txt", 'w') as file:
  file.write_line("hello world!")

with open("some_file.txt", 'r') as file:
  while not end_of_file(file):
    print(file.read_line())

with NamedTemporaryFile() as file:
  file.write_line("test!")

with TemporaryDirectory() as name:
  print(name)

type Example = ref object
  start: int
  stop: int
  step: int

class Example(object):  # Mimic simple Python "classes".
  """Example class with Python-ish Nim syntax!."""

  def init(self, start, stop, step=1):
    self.start = start
    self.stop = stop
    self.step = step

  def stopit(self, argument):
    """Example function with Python-ish Nim syntax."""
    self.stop = argument
    return self.stop

let e = newExample(5, 3)
print(e.stopit(5))

Nimpylib heavily relies on Nim generics, converters, operator overloading, and even on concepts.

Installation

To install nimpylib, you can simply run

nimble install pylib

Requisites

Supported features

  • [x] F-Strings f"foo {variable} bar {1 + 2} baz" and string functions
  • [x] Python-like variable unpacking
  • [x] Math with Float and Int mixed like Python.
  • [x] import antigravity
  • [x] from __future__ import braces
  • [x] lambda:
  • [x] with open("file.ext", 'w'): Read, write, append, and file.read().
  • [x] with tempfile.TemporaryDirectory(): Read, write, append, and file.read().
  • [x] with tempfile.NamedTemporaryFile() as file: Read, write, append, and file.read().
  • [x] timeit() with Nanoseconds precision
  • [x] json.loads() also can Pretty-Print
  • [x] True / False
  • [x] pass also can take and discard any arguments
  • [x] := Walrus Operator
  • [x] {"a": 1} | {"b": 2} Dict merge operator
  • [x] |= Dict merge operator
  • [x] Python-like OOP class with methods and DocStrings (without inheritance)
  • [x] abs()
  • [x] all()
  • [x] any()
  • [x] bin()
  • [x] chr()
  • [x] divmod()
  • [x] enumerate()
  • [x] filter()
  • [x] float()
  • [x] hex()
  • [x] input()
  • [x] int()
  • [x] iter()
  • [x] list()
  • [x] map()
  • [x] max()
  • [x] min()
  • [x] oct()
  • [x] ord()
  • [x] print("foo") / print "foo" Python2 like
  • [x] range() but named xrange() like in Python 2
  • [x] str()
  • [x] sum()
  • [x] <> Python1 and Python2 !=
  • [x] long() Python2 like
  • [x] unicode() Python2 like
  • [x] ascii() Python2 like
  • [x] u"string here" / u'a' Python2 like
  • [x] b"string here" / b'a' Python2 like
  • [ ] isinstance()
  • [ ] issubclass()
  • [ ] id()
  • More...

Other Python-like modules

Tests

$ nimble test
[OK] Range-like Nim procedure
[OK] Floor division
[OK] Class macro
[OK] tonim macro
[OK] String operations
[OK] Modulo operations
2020-06-17T22:07:28+03:00 TimeIt: 9 Repetitions on 118 microseconds and 711 nanoseconds, CPU Time 5.740999999999993e-05.
[OK] Miscelaneous
[OK] unpack macro

Stats

Star nimpylib on GitHub

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].