The nimformat library is the result of an experiment in using the excellent nimpy module, for the awesome Nim programming language, to create a test library, for Python. The goal was to learn some about Nim, nimpy, creating native Python modules, and to see what, if any, speed boosts could be realized.
The `nim_sub()` function is a rudimentary implementation of string substitution in a similar way to how Python accepts a dictionary for its `string.format()`.
The Nim native Python library can be built by issuing the following command.
`nim c --threads:on --app:lib --out:nimformat.pyd --tlsEmulation:off nimformat.nim`
NOTE: This was done using the latest development version of Nim, which is 0.19.9 at the time of this writing.
Simple benchmarks with Python's `timeit` module yield the following results. See `test_nimformat.py` for more details.
```
Pure Python time : 1.7126781147680623e-05
Pure Python [no locals()] time : 1.8929600215857533e-05
Nim dylib time : 0.2829040771053697
Nim dylib [no locals()] time : 0.0016501803870713205
Nim dylib sub_multi time : 0.29930432216857517
Nim dylib sub_multi [no locals()] time : 0.0007848272343464746
```
Example 1:
```
import nimformat
variable1 = 'string'
variable2 = 'contains'
dictSub = dict(locals())
dictSub = {str(key): str(dictSub[key]) for key in dictSub.keys() if '__' not in str(key)}
strWithSubstitutions = """
This is a {variable1} which spans
multiple lines and {variable2} multiple
substitutions.
"""
strSubstituted = nimformat.nim_sub(strWithSubstitutions, dictSub)
```
Example 2:
```
import nimformat
dictSub = {
'variable1': 'string',
'variable2': 'contains'
}
strWithSubstitutions = """
This is a {variable1} which spans
multiple lines and {variable2} multiple
substitutions.
"""
strSubstituted = nimformat.nim_sub(strWithSubstitutions, dictSub)
```
Metadata
Release files for nimformat 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nimformat-0.1.3.zip | 153.0 kB | Without provenance | Details for nimformat-0.1.3.zip |
Release files / nimformat-0.1.3.zip
| Download URL | nimformat-0.1.3.zip |
|---|---|
| Size | 153.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a30cee0c14b9b57375d01ce1f98a3a1344e8e86534e5f3f23ce4badf18cccbf
|
|
BLAKE2b-256 checksum How to use checksums |
ff7174d981e4f8d52d41d8cad76b31654c0c615cf442f379298d7c1c59ec81e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for nimformat 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.