/python-to-rust

A Rust guide for Python programmer/developer.

Primary LanguageRust

py2rs

From Python into Rust

let x = Rust::from("Python");

A quick reference guide for the Pythonista in process of becoming a Rustacean.

A Rust guide for Python programmer/developer.

image_2017-11-28_08-03-59

Monty Python - Season 3 - Episode 49

The sketch

Mrs. Jalin: George.
Mr. Jalin: Yes, Gladys.
Mrs. Jalin: There's a man at the door with a moustache.
Mr. Jalin: Tell him I've already got one. (Mrs. Jalin hits him hard with a newspaper) 
          All right, all right. What's he want then?
Mrs. Jalin: He says do we want a documentary on crustaceans.
Mr. Jalin: Crustaceans!
Mrs. Jalin: Yes.
Mr. Jalin: What's he mean, crustaceans?
Mrs. Jalin: CRUSTACEANS!! GASTROPODS! LAMELLIBRANCHS! CEPHALOPODS!
...

Ok... watch it later... let's learn some Rust now...

TOC

Getting Started with Rust

Assuming you already know what is Rust and already decided to start learning it. Here are some steps for you to follow:

  1. Take a tour of Rust Syntax and Coding Style
    https://learnxinyminutes.com/docs/rust/
  2. Watch some screencasts to get basics of Ownership &Borrowing concept
    http://intorust.com/
  3. Follow this set of runnable examples to understand how everything fit together
    https://doc.rust-lang.org/stable/rust-by-example/
  4. Now it is time to read your first book, you can pick:
  5. Read some real examples
  6. Patterns and Good Practices

Exercises

Time to put your new knowledge in action solving some exercises.

  1. Exercism.io
    Register a new account on exercism.io (using github auth)
    Install exercism command line client on your computer
    Solve some exercises: https://www.exercism.io/languages/rust/

  2. Rust Playground
    Run Live Rust Code in the browser with https://play.rust-lang.org/

  3. rustlings
    Interactive rust exercises: https://github.com/rust-lang/rustlings

Getting updated

Now I assume you are addicted to Rust and you want to be updated about everything around it, here are some good links to follow.

  1. This Week in Rust Newsletter
    https://this-week-in-rust.org/
    https://twitter.com/thisweekinrust
  2. Awesome Rust Newsletter
    https://rust.libhunt.com/
  3. Reddit
    http://reddit.com/r/rust (serious sub-reddit)
    http://reddit.com/r/rustjerk (almost memes only)
  4. Official Twitter
    https://twitter.com/rustlang

Interact with other Rustaceans

Don't be afraid, the Rustaceans are a very receptive species and are cozy with the Pythonistas.

Main Community links

https://www.rust-lang.org/en-US/community.html

Local Communities

Additional learning resources

Facts

  • The language is named Rust because "rust is as close to the bare metal as you can get".,
    in metal theory rust is the chemical layer closest to bare metal.
    (also Wikipedia says that the name was possibly inspired by the name of a Fungi)
  • The Rust trifecta is 1) Memory Safe, 2) Fast 3) Concurrent
  • Rust can be used for web development http://www.arewewebyet.org/
  • Rust can be used for Gaming Development http://arewegameyet.com/
  • Rust can be used for Machine Learning http://www.arewelearningyet.com/
  • Lots of IDEs and Editors supports Rust https://areweideyet.com/
    (VSCode is known to have the better support by now https://marketplace.visualstudio.com/items?itemName=kalitaalexey.vscode-rust)
  • Rust packages are called Crates and are installed by Cargo explore them at http://crates.io
  • In Rust there is no Class but Structs, Enums, Traits, functions and macros!
  • Rust compiler was first written in OCaml then rewritten in Rust! (Rust is written in Rust!!!)
  • Rust type system is strongly inspired by Haskell
  • Rust functional style is inspired by Erlang
  • Rust type inference is mainly inspired by ML and also by Haskell
  • The main syntax style is inspired by C and C++
  • There is no automated Garbage Collector so Rust frees memory based on Resource Aquisition RAII (a.k.a Ownership)
  • Rust has Generic Types!!!
  • As Rust is close to bare metal you can ship a program without the inclusion of Rust's runtime which makes easy to distribute programs (no need of dependencies and virtuelenvs management)
  • There are Python code in Rust! Rust build is bootstrapped by Python
  • Graydon Hoare (creator of Rust) is now working at Apple developing the Swift language
  • Rust is the developers most loved language according to Stack Overflow Survey
  • Rust is the most energy efficient language! and that is very important for environment, data center companies and maybe it can help saving your laptop and phone battery in near future.
  • There is an Operating System written in Rust - https://www.redox-os.org/
  • Mozilla released the fastest version of Firefox (quantum) having many parts written on Rust
  • The Rust mascot (unofficial) is called Ferris and it is a crab http://www.rustacean.net/
    (There is no record of the official reason about being a crab, the reasonable history is that it was inspired by the Rusty Crab a common species of crab and also a name of a famous restaurant.)
  • To compliment your fellow Rustaceans don't say cheers!. Say safe! (safe! is also said when toasting with champagne at Rust conferences)
  • Rust is to become a second programming language for the Linux kernel (see here)

More facts? and curiosities send a question here or send a Pull Request adding an interest fact to this list.

ferris

Glossary of terms

Term Definition
crate A rust distributable package
ferris The unofficial Crab Mascot
Rustacean The Rust programmer or evangelist or enthusiastic
nightly The unstable toolchain of the Rust compiler
impl Implementation

General

Python Definition Rust
PEP8 Guidelines and conventions RustAPI Guidelines
PEPS Enhancement Proposals / RFC Rust RFCs
PSF Organization / Foundation Mozilla Research
PyCon Main Conference RustConf
Guido Van Rossum Creator Graydon Hoare
1989 First appeared 2010
1991 First Release 2012
PSF License Apache 2.0 and MIT
C Implemented in Rust
.py, .pyw, .pyc File Extensions .rs, .rlib
http://github.com/python/cpython Repository https://github.com/rust-lang/rust
Pyladies, AfroPython Diversity and Inclusion initiative RustBridge
comp.lang.Python Official Users Forum users.rust-lang.org

Environment Tools

Python Definition Rust
requirements.txt Official dependency tracker file Cargo.toml
setup.py Official installator / distributor file Cargo.toml
PyPI Library repository Crates.io
pip Library installation Cargo
setuptools and poetry Library distribution Cargo
pbr Library distribution Cargo
pipenv and poetry Dependency manager Cargo
twine Package uploader Cargo and Semantic
venv * Isolated environments Cargo
pyinstaller Generate standalone executables Cargo
pyenv Install and manage versions of language rustup
pydoc and sphinx Generate documentation from code rustdoc and Cargo
python Interpreter / Compiler rustc and Cargo
ipython REPL rusti
ipdb Debugger rust-gdb
Extending Python with C or C++ Foreign language interface PyO3

Libraries and Frameworks

Python Definition Rust
urllib * HTTP calls hyper
requests Simplified HTTP calls reqwest
json JSON parsing loading and dumping serde
pyYAML YAML parsing loading and dumping serde
lxml XML parsing loading and dumping RustyXML
csv * CSV parsing rust-csv
datetime * & Dateutils Date & time Chrono
click and argparse CLI Framework clap
docopt CLI Framework docopt
re * Regular Expressions regex
subprocess * Run external commands subprocess
multiprocessing * Multiprocessing Rayon
logging * Logging log
Pathlib * Path manipulation fs and fs_extra
cryptography Crytography crypto
pickle * Object serialization RON
heapq * Heap queue BinaryHeap *
bottle Minimal web framework Iron
flask Web framework Rocket
django Full stack web framework DO NOT EXIST YET
SQL Alchemy Relational database ORM Diesel
Pymongo MongoDB driver mongodb
Jinja 2 Template engine Tera
pygtk GTk desktop development gtk
pyside QT desktop development rust-qt
pygame 2D UI library / gaming ggez & Conrod & Piston
unitest2 Test framework Builtin
nose Test runner Cargo
pytest Testing framework and runner Polish
Flake8 Linter Clippy
autopep8 and black Auto formatter rustfmt
twisted Network application framework libpnet
AsyncIO * Async application framework Tokio and futures
Pillow Image manipulation Image
Beautiful Soup HTML parser html5ever
Hypothesis Data driven test framework Quickcheck and proptest
mock Test mocking Mockers
bioPython Bioinformathics libraries Rust Bio
Dynaconf Config management Config
itertools * Data structure iteration Rust Itertools
Geopython Geo spatial data Geo Rust
ScikitLearn Machine learning rusty-machine
mistune Markdown / Common Mark Parser cmark
celery Distributed computation Antimony
boto AWS clients rusoto
AstroPy Astronomy astro-rust
Numpy Numeric ndarray
Pandas Dataframes Polars

Applications

Python Definition Rust
Pelican Static Site generator Cobalt
ansible Infra Orchestration realize
mkdocs Generate documentation and e-books from Markdown mdBook
locust HTTP load test drill
Nameko Microservices Framework fractalide
Quokka CMS CMS Nickel CMS

Useful crates

Add Pythonic features to Rust

Python Definition Rust
{'foo': "bar"} Syntax to create a dict / hashmap maplit
__init__(self, value='default') Instance initialization (with some default values) derive_new
itertools *stdlib Extra iterators methods itertools
hashlib * Password Hashing libpasta